fix(posthog): disable feature flags, remove plugin_loaded event for billing optimization
- Remove plugin_loaded telemetry from index.ts (was 46.5% of all events, ~2.83M/month) - Add enableLocalEvaluation: false to prevent feature flag polling/decide calls - Add strictLocalEvaluation: true to prevent server fallback requests - Add disableRemoteConfig: true to prevent remote config network requests - Remove 'plugin_loaded' from PostHogActivityReason type - Update tests: remove stale mocks, add SDK options verification test - enableExceptionAutocapture: false already present (kept) Estimated billing reduction: ~$960+/month from feature flag requests, plus ~2.83M fewer events/month from plugin_loaded removal.
This commit is contained in:
@@ -67,7 +67,7 @@ describe("posthog client creation", () => {
|
||||
expect(() => cliPostHog.trackActive("cli", "run_started")).not.toThrow()
|
||||
await expect(cliPostHog.shutdown()).resolves.toBeUndefined()
|
||||
|
||||
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
|
||||
expect(() => pluginPostHog.trackActive("plugin", "run_started")).not.toThrow()
|
||||
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
||||
})
|
||||
|
||||
@@ -104,9 +104,44 @@ describe("posthog client creation", () => {
|
||||
const pluginPostHog = createPluginPostHog()
|
||||
|
||||
// then
|
||||
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
|
||||
expect(() => pluginPostHog.trackActive("plugin", "run_started")).not.toThrow()
|
||||
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
||||
})
|
||||
|
||||
it("passes the strict PostHog constructor options for both clients", async () => {
|
||||
// given
|
||||
enableTelemetryEnv()
|
||||
const capturedOptions: Array<Record<string, unknown>> = []
|
||||
|
||||
mock.module("posthog-node", () => ({
|
||||
PostHog: class {
|
||||
constructor(_apiKey: string, options: Record<string, unknown>) {
|
||||
capturedOptions.push(options)
|
||||
}
|
||||
capture() {}
|
||||
async shutdown() {}
|
||||
},
|
||||
}))
|
||||
|
||||
const { createCliPostHog, createPluginPostHog } = await importPostHogModule()
|
||||
|
||||
// when
|
||||
createCliPostHog()
|
||||
createPluginPostHog()
|
||||
|
||||
// then
|
||||
expect(capturedOptions).toHaveLength(2)
|
||||
for (const options of capturedOptions) {
|
||||
expect(options).toMatchObject({
|
||||
enableExceptionAutocapture: false,
|
||||
enableLocalEvaluation: false,
|
||||
strictLocalEvaluation: true,
|
||||
disableRemoteConfig: true,
|
||||
flushAt: 1,
|
||||
flushInterval: 0,
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe("posthog trackActive emission contract", () => {
|
||||
@@ -170,7 +205,7 @@ describe("posthog trackActive emission contract", () => {
|
||||
const client = posthogModule.createPluginPostHog()
|
||||
|
||||
// when
|
||||
client.trackActive("distinct-plugin", "plugin_loaded")
|
||||
client.trackActive("distinct-plugin", "run_started")
|
||||
|
||||
// then
|
||||
expect(captured).toHaveLength(0)
|
||||
|
||||
@@ -29,7 +29,7 @@ const DEFAULT_POSTHOG_API_KEY = "phc_CFJhj5HyvA62QPhvyaUCtaq23aUfznnijg5VaaGkNk7
|
||||
|
||||
type PostHogCaptureEvent = Parameters<PostHog["capture"]>[0]
|
||||
type PostHogSource = "cli" | "plugin"
|
||||
type PostHogActivityReason = "run_started" | "plugin_loaded"
|
||||
type PostHogActivityReason = "run_started"
|
||||
|
||||
type PostHogClient = {
|
||||
trackActive: (distinctId: string, reason: PostHogActivityReason) => void
|
||||
@@ -151,6 +151,9 @@ export function getPostHogDistinctId(): string {
|
||||
export function createCliPostHog(): PostHogClient {
|
||||
return createPostHogClient("cli", {
|
||||
enableExceptionAutocapture: false,
|
||||
enableLocalEvaluation: false,
|
||||
strictLocalEvaluation: true,
|
||||
disableRemoteConfig: true,
|
||||
flushAt: 1,
|
||||
flushInterval: 0,
|
||||
})
|
||||
@@ -159,6 +162,9 @@ export function createCliPostHog(): PostHogClient {
|
||||
export function createPluginPostHog(): PostHogClient {
|
||||
return createPostHogClient("plugin", {
|
||||
enableExceptionAutocapture: false,
|
||||
enableLocalEvaluation: false,
|
||||
strictLocalEvaluation: true,
|
||||
disableRemoteConfig: true,
|
||||
flushAt: 1,
|
||||
flushInterval: 0,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user