refactor(telemetry): narrow PostHog client and mark omo_daily_active anonymous
This commit is contained in:
@@ -29,7 +29,6 @@ function mockPostHogNode(capturedMessages: CapturedPostHogMessage[]): void {
|
|||||||
capture(message: CapturedPostHogMessage): void {
|
capture(message: CapturedPostHogMessage): void {
|
||||||
capturedMessages.push(message)
|
capturedMessages.push(message)
|
||||||
}
|
}
|
||||||
captureException(): void {}
|
|
||||||
async shutdown(): Promise<void> {}
|
async shutdown(): Promise<void> {}
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
@@ -65,23 +64,9 @@ describe("posthog client creation", () => {
|
|||||||
const pluginPostHog = createPluginPostHog()
|
const pluginPostHog = createPluginPostHog()
|
||||||
|
|
||||||
// then
|
// 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()
|
expect(() => cliPostHog.trackActive("cli", "run_started")).not.toThrow()
|
||||||
await expect(cliPostHog.shutdown()).resolves.toBeUndefined()
|
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()
|
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
|
||||||
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
||||||
})
|
})
|
||||||
@@ -109,7 +94,6 @@ describe("posthog client creation", () => {
|
|||||||
mock.module("posthog-node", () => ({
|
mock.module("posthog-node", () => ({
|
||||||
PostHog: class {
|
PostHog: class {
|
||||||
capture() {}
|
capture() {}
|
||||||
captureException() {}
|
|
||||||
async shutdown() {}
|
async shutdown() {}
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
@@ -120,13 +104,6 @@ describe("posthog client creation", () => {
|
|||||||
const pluginPostHog = createPluginPostHog()
|
const pluginPostHog = createPluginPostHog()
|
||||||
|
|
||||||
// then
|
// 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()
|
expect(() => pluginPostHog.trackActive("plugin", "plugin_loaded")).not.toThrow()
|
||||||
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
await expect(pluginPostHog.shutdown()).resolves.toBeUndefined()
|
||||||
})
|
})
|
||||||
@@ -174,6 +151,7 @@ describe("posthog trackActive emission contract", () => {
|
|||||||
day_utc: "2026-04-18",
|
day_utc: "2026-04-18",
|
||||||
reason: "run_started",
|
reason: "run_started",
|
||||||
source: "cli",
|
source: "cli",
|
||||||
|
$process_person_profile: false,
|
||||||
})
|
})
|
||||||
expect(dailyEvent?.properties).not.toHaveProperty("hour_utc")
|
expect(dailyEvent?.properties).not.toHaveProperty("hour_utc")
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-24
@@ -28,24 +28,15 @@ const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com"
|
|||||||
const DEFAULT_POSTHOG_API_KEY = "phc_CFJhj5HyvA62QPhvyaUCtaq23aUfznnijg5VaaGkNk74"
|
const DEFAULT_POSTHOG_API_KEY = "phc_CFJhj5HyvA62QPhvyaUCtaq23aUfznnijg5VaaGkNk74"
|
||||||
|
|
||||||
type PostHogCaptureEvent = Parameters<PostHog["capture"]>[0]
|
type PostHogCaptureEvent = Parameters<PostHog["capture"]>[0]
|
||||||
type PostHogExceptionProperties = Parameters<PostHog["captureException"]>[2]
|
|
||||||
type PostHogSource = "cli" | "plugin"
|
type PostHogSource = "cli" | "plugin"
|
||||||
type PostHogActivityReason = "run_started" | "plugin_loaded"
|
type PostHogActivityReason = "run_started" | "plugin_loaded"
|
||||||
|
|
||||||
type PostHogClient = {
|
type PostHogClient = {
|
||||||
capture: (message: PostHogCaptureEvent) => void
|
|
||||||
captureException: (
|
|
||||||
error: unknown,
|
|
||||||
distinctId?: string,
|
|
||||||
additionalProperties?: PostHogExceptionProperties,
|
|
||||||
) => void
|
|
||||||
trackActive: (distinctId: string, reason: PostHogActivityReason) => void
|
trackActive: (distinctId: string, reason: PostHogActivityReason) => void
|
||||||
shutdown: () => Promise<void>
|
shutdown: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const NO_OP_POSTHOG: PostHogClient = {
|
const NO_OP_POSTHOG: PostHogClient = {
|
||||||
capture: () => undefined,
|
|
||||||
captureException: () => undefined,
|
|
||||||
trackActive: () => undefined,
|
trackActive: () => undefined,
|
||||||
shutdown: async () => undefined,
|
shutdown: async () => undefined,
|
||||||
}
|
}
|
||||||
@@ -131,21 +122,6 @@ function createPostHogClient(
|
|||||||
const sharedProperties = getSharedProperties(source)
|
const sharedProperties = getSharedProperties(source)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
capture: (message) => {
|
|
||||||
configuredClient.capture({
|
|
||||||
...message,
|
|
||||||
properties: {
|
|
||||||
...sharedProperties,
|
|
||||||
...message.properties,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
captureException: (error, distinctId, additionalProperties) => {
|
|
||||||
configuredClient.captureException(error, distinctId, {
|
|
||||||
...sharedProperties,
|
|
||||||
...additionalProperties,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
trackActive: (distinctId, reason) => {
|
trackActive: (distinctId, reason) => {
|
||||||
const activityState = resolveActivityState()
|
const activityState = resolveActivityState()
|
||||||
|
|
||||||
@@ -155,6 +131,7 @@ function createPostHogClient(
|
|||||||
event: "omo_daily_active",
|
event: "omo_daily_active",
|
||||||
properties: {
|
properties: {
|
||||||
...sharedProperties,
|
...sharedProperties,
|
||||||
|
$process_person_profile: false,
|
||||||
day_utc: activityState.dayUTC,
|
day_utc: activityState.dayUTC,
|
||||||
reason,
|
reason,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user