Merge pull request #3830 from code-yeongyu/fix/posthog-billing-optimization
fix(posthog): disable feature flags, remove plugin_loaded for billing optimization
This commit is contained in:
@@ -39,8 +39,6 @@ describe("runCliInstaller telemetry isolation", () => {
|
|||||||
mock.module("../shared/posthog", () => ({
|
mock.module("../shared/posthog", () => ({
|
||||||
createCliPostHog: mock(() => ({
|
createCliPostHog: mock(() => ({
|
||||||
trackActive: mock(() => {}),
|
trackActive: mock(() => {}),
|
||||||
capture: mock(() => {}),
|
|
||||||
captureException: mock(() => {}),
|
|
||||||
shutdown: mock(async () => {
|
shutdown: mock(async () => {
|
||||||
throw new Error("shutdown failed")
|
throw new Error("shutdown failed")
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -30,14 +30,6 @@ const mockCreateHooks = mock(() => ({
|
|||||||
claudeCodeHooks: undefined,
|
claudeCodeHooks: undefined,
|
||||||
}))
|
}))
|
||||||
const mockCreatePluginInterface = mock(() => ({}))
|
const mockCreatePluginInterface = mock(() => ({}))
|
||||||
const mockCreatePluginPostHog = mock(() => ({
|
|
||||||
trackActive: () => {
|
|
||||||
throw new Error("telemetry failed")
|
|
||||||
},
|
|
||||||
shutdown: mock(async () => {}),
|
|
||||||
}))
|
|
||||||
const mockGetPostHogDistinctId = mock(() => "plugin-distinct-id")
|
|
||||||
|
|
||||||
function installModuleMocks(): void {
|
function installModuleMocks(): void {
|
||||||
mock.module("./cli/config-manager/config-context", () => ({
|
mock.module("./cli/config-manager/config-context", () => ({
|
||||||
initConfigContext: mockInitConfigContext,
|
initConfigContext: mockInitConfigContext,
|
||||||
@@ -98,10 +90,6 @@ function installModuleMocks(): void {
|
|||||||
cleanupTempDirectoryClients: mock(async () => {}),
|
cleanupTempDirectoryClients: mock(async () => {}),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
mock.module("./shared/posthog", () => ({
|
|
||||||
createPluginPostHog: mockCreatePluginPostHog,
|
|
||||||
getPostHogDistinctId: mockGetPostHogDistinctId,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("oh-my-openagent telemetry isolation", () => {
|
describe("oh-my-openagent telemetry isolation", () => {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import { injectServerAuthIntoClient, log, logLegacyPluginStartupWarning } from "
|
|||||||
import { installAgentSortShim } from "./shared/agent-sort-shim"
|
import { installAgentSortShim } from "./shared/agent-sort-shim"
|
||||||
import { detectExternalSkillPlugin, getSkillPluginConflictWarning } from "./shared/external-plugin-detector"
|
import { detectExternalSkillPlugin, getSkillPluginConflictWarning } from "./shared/external-plugin-detector"
|
||||||
import { startBackgroundCheck as startTmuxCheck } from "./tools/interactive-bash"
|
import { startBackgroundCheck as startTmuxCheck } from "./tools/interactive-bash"
|
||||||
import { createPluginPostHog, getPostHogDistinctId } from "./shared/posthog"
|
|
||||||
|
|
||||||
const serverPlugin: Plugin = async (input, _options): Promise<Hooks> => {
|
const serverPlugin: Plugin = async (input, _options): Promise<Hooks> => {
|
||||||
installAgentSortShim()
|
installAgentSortShim()
|
||||||
@@ -36,13 +35,6 @@ const serverPlugin: Plugin = async (input, _options): Promise<Hooks> => {
|
|||||||
|
|
||||||
const pluginConfig = loadPluginConfig(input.directory, input)
|
const pluginConfig = loadPluginConfig(input.directory, input)
|
||||||
|
|
||||||
const posthog = createPluginPostHog()
|
|
||||||
const distinctId = getPostHogDistinctId()
|
|
||||||
try {
|
|
||||||
posthog.trackActive(distinctId, "plugin_loaded")
|
|
||||||
} catch {
|
|
||||||
// telemetry failure is non-fatal, silently ignore
|
|
||||||
}
|
|
||||||
if (pluginConfig.openclaw) {
|
if (pluginConfig.openclaw) {
|
||||||
await initializeOpenClaw(pluginConfig.openclaw)
|
await initializeOpenClaw(pluginConfig.openclaw)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ describe("posthog client creation", () => {
|
|||||||
expect(() => cliPostHog.trackActive("cli", "run_started")).not.toThrow()
|
expect(() => cliPostHog.trackActive("cli", "run_started")).not.toThrow()
|
||||||
await expect(cliPostHog.shutdown()).resolves.toBeUndefined()
|
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()
|
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -104,9 +104,44 @@ describe("posthog client creation", () => {
|
|||||||
const pluginPostHog = createPluginPostHog()
|
const pluginPostHog = createPluginPostHog()
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
|
expect(() => pluginPostHog.trackActive("plugin", "run_started")).not.toThrow()
|
||||||
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
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", () => {
|
describe("posthog trackActive emission contract", () => {
|
||||||
@@ -170,7 +205,7 @@ describe("posthog trackActive emission contract", () => {
|
|||||||
const client = posthogModule.createPluginPostHog()
|
const client = posthogModule.createPluginPostHog()
|
||||||
|
|
||||||
// when
|
// when
|
||||||
client.trackActive("distinct-plugin", "plugin_loaded")
|
client.trackActive("distinct-plugin", "run_started")
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(captured).toHaveLength(0)
|
expect(captured).toHaveLength(0)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const DEFAULT_POSTHOG_API_KEY = "phc_CFJhj5HyvA62QPhvyaUCtaq23aUfznnijg5VaaGkNk7
|
|||||||
|
|
||||||
type PostHogCaptureEvent = Parameters<PostHog["capture"]>[0]
|
type PostHogCaptureEvent = Parameters<PostHog["capture"]>[0]
|
||||||
type PostHogSource = "cli" | "plugin"
|
type PostHogSource = "cli" | "plugin"
|
||||||
type PostHogActivityReason = "run_started" | "plugin_loaded"
|
type PostHogActivityReason = "run_started"
|
||||||
|
|
||||||
type PostHogClient = {
|
type PostHogClient = {
|
||||||
trackActive: (distinctId: string, reason: PostHogActivityReason) => void
|
trackActive: (distinctId: string, reason: PostHogActivityReason) => void
|
||||||
@@ -151,6 +151,9 @@ export function getPostHogDistinctId(): string {
|
|||||||
export function createCliPostHog(): PostHogClient {
|
export function createCliPostHog(): PostHogClient {
|
||||||
return createPostHogClient("cli", {
|
return createPostHogClient("cli", {
|
||||||
enableExceptionAutocapture: false,
|
enableExceptionAutocapture: false,
|
||||||
|
enableLocalEvaluation: false,
|
||||||
|
strictLocalEvaluation: true,
|
||||||
|
disableRemoteConfig: true,
|
||||||
flushAt: 1,
|
flushAt: 1,
|
||||||
flushInterval: 0,
|
flushInterval: 0,
|
||||||
})
|
})
|
||||||
@@ -159,6 +162,9 @@ export function createCliPostHog(): PostHogClient {
|
|||||||
export function createPluginPostHog(): PostHogClient {
|
export function createPluginPostHog(): PostHogClient {
|
||||||
return createPostHogClient("plugin", {
|
return createPostHogClient("plugin", {
|
||||||
enableExceptionAutocapture: false,
|
enableExceptionAutocapture: false,
|
||||||
|
enableLocalEvaluation: false,
|
||||||
|
strictLocalEvaluation: true,
|
||||||
|
disableRemoteConfig: true,
|
||||||
flushAt: 1,
|
flushAt: 1,
|
||||||
flushInterval: 0,
|
flushInterval: 0,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user