refactor(telemetry): narrow PostHog client and mark omo_daily_active anonymous

This commit is contained in:
YeonGyu-Kim
2026-05-02 00:11:01 +09:00
parent b8a5f27dee
commit 92dab9285c
2 changed files with 2 additions and 47 deletions
+1 -23
View File
@@ -29,7 +29,6 @@ function mockPostHogNode(capturedMessages: CapturedPostHogMessage[]): void {
capture(message: CapturedPostHogMessage): void {
capturedMessages.push(message)
}
captureException(): void {}
async shutdown(): Promise<void> {}
},
}))
@@ -65,23 +64,9 @@ describe("posthog client creation", () => {
const pluginPostHog = createPluginPostHog()
// then
expect(() =>
cliPostHog.capture({
distinctId: "cli",
event: "run_started",
}),
).not.toThrow()
expect(() => cliPostHog.captureException(new Error("cli failure"), "cli")).not.toThrow()
expect(() => cliPostHog.trackActive("cli", "run_started")).not.toThrow()
await expect(cliPostHog.shutdown()).resolves.toBeUndefined()
expect(() =>
pluginPostHog.capture({
distinctId: "plugin",
event: "plugin_loaded",
}),
).not.toThrow()
expect(() => pluginPostHog.captureException(new Error("plugin failure"), "plugin")).not.toThrow()
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
})
@@ -109,7 +94,6 @@ describe("posthog client creation", () => {
mock.module("posthog-node", () => ({
PostHog: class {
capture() {}
captureException() {}
async shutdown() {}
},
}))
@@ -120,13 +104,6 @@ describe("posthog client creation", () => {
const pluginPostHog = createPluginPostHog()
// then
expect(() =>
pluginPostHog.capture({
distinctId: "plugin",
event: "plugin_loaded",
}),
).not.toThrow()
expect(() => pluginPostHog.captureException(new Error("plugin failure"), "plugin")).not.toThrow()
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
})
@@ -174,6 +151,7 @@ describe("posthog trackActive emission contract", () => {
day_utc: "2026-04-18",
reason: "run_started",
source: "cli",
$process_person_profile: false,
})
expect(dailyEvent?.properties).not.toHaveProperty("hour_utc")
})
+1 -24
View File
@@ -28,24 +28,15 @@ const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com"
const DEFAULT_POSTHOG_API_KEY = "phc_CFJhj5HyvA62QPhvyaUCtaq23aUfznnijg5VaaGkNk74"
type PostHogCaptureEvent = Parameters<PostHog["capture"]>[0]
type PostHogExceptionProperties = Parameters<PostHog["captureException"]>[2]
type PostHogSource = "cli" | "plugin"
type PostHogActivityReason = "run_started" | "plugin_loaded"
type PostHogClient = {
capture: (message: PostHogCaptureEvent) => void
captureException: (
error: unknown,
distinctId?: string,
additionalProperties?: PostHogExceptionProperties,
) => void
trackActive: (distinctId: string, reason: PostHogActivityReason) => void
shutdown: () => Promise<void>
}
const NO_OP_POSTHOG: PostHogClient = {
capture: () => undefined,
captureException: () => undefined,
trackActive: () => undefined,
shutdown: async () => undefined,
}
@@ -131,21 +122,6 @@ function createPostHogClient(
const sharedProperties = getSharedProperties(source)
return {
capture: (message) => {
configuredClient.capture({
...message,
properties: {
...sharedProperties,
...message.properties,
},
})
},
captureException: (error, distinctId, additionalProperties) => {
configuredClient.captureException(error, distinctId, {
...sharedProperties,
...additionalProperties,
})
},
trackActive: (distinctId, reason) => {
const activityState = resolveActivityState()
@@ -155,6 +131,7 @@ function createPostHogClient(
event: "omo_daily_active",
properties: {
...sharedProperties,
$process_person_profile: false,
day_utc: activityState.dayUTC,
reason,
},