Back to all reviewers

API initialization side effects

PostHog/posthog
Based on 2 comments
Html

When initializing API clients, prefer bootstrap/configuration patterns over method calls that may trigger unintended side effects like billing events, data capture, or state changes. Method calls during initialization can have unexpected consequences that users may not anticipate or want to pay for.

API Html

Reviewer Prompt

When initializing API clients, prefer bootstrap/configuration patterns over method calls that may trigger unintended side effects like billing events, data capture, or state changes. Method calls during initialization can have unexpected consequences that users may not anticipate or want to pay for.

Instead of calling methods like identify(), capture(), or similar action-triggering functions during client setup, use configuration objects, bootstrap data, or initialization parameters to achieve the same result without side effects.

Example of problematic initialization:

// This triggers an identify event that users get billed for
posthog.init(token, config);
posthog.identify(distinctId); // Captures billable event

Preferred approach using bootstrap configuration:

// This achieves the same result without capturing events
const config = {
    api_host: projectConfig.api_host,
    bootstrap: {
        distinctId: distinctId // Set identity without triggering events
    }
};
posthog.init(token, config);

This pattern ensures that client initialization only sets up the necessary state without triggering actions that have business implications or costs. Always consider whether initialization methods have side effects and prefer declarative configuration approaches when available.

2
Comments Analyzed
Html
Primary Language
API
Category

Source Discussions