Skip to content

Commit 550ea30

Browse files
fix: upgrade posthog-node to v5 to fix missing telemetry events (#28)
posthog-node v4's `captureImmediate` had a bug where the `.then()` chain didn't return the promise from `captureStatelessImmediate`, causing the HTTP request to be fire-and-forget. Combined with trpc-cli calling `process.exit()` after the handler completes, telemetry events were silently dropped before the request could finish. This upgrades posthog-node from 4.18.0 to 5.28.2 where the bug is fixed, and removes the deprecated `captureMode` and `persistence` options that no longer exist in v5.
1 parent ee3ff63 commit 550ea30

3 files changed

Lines changed: 14 additions & 57 deletions

File tree

bun.lock

Lines changed: 4 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"execa": "^9.6.1",
5353
"fs-extra": "^11.3.3",
5454
"handlebars": "^4.7.8",
55-
"posthog-node": "4.18.0",
55+
"posthog-node": "^5.28.2",
5656
"trpc-cli": "^0.12.4",
5757
"zod": "^4.3.6"
5858
},

src/telemetry/client.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,24 @@ export async function trackCliTelemetry(
117117

118118
let client: PostHog | undefined;
119119
try {
120+
const distinctId = await getAnonymousId();
121+
const sanitizedProperties = sanitizeProperties({
122+
...getCommonProperties(),
123+
...properties,
124+
$process_person_profile: false,
125+
});
126+
120127
client = new PostHog(TELEMETRY_API_KEY, {
121128
host: TELEMETRY_HOST,
122-
captureMode: "json",
123129
disableGeoip: true,
124130
flushAt: 1,
125131
flushInterval: 0,
126-
persistence: "memory",
127132
});
128133

129134
await client.captureImmediate({
130-
distinctId: await getAnonymousId(),
135+
distinctId,
131136
event,
132-
properties: sanitizeProperties({
133-
...getCommonProperties(),
134-
...properties,
135-
$process_person_profile: false,
136-
}),
137+
properties: sanitizedProperties,
137138
disableGeoip: true,
138139
});
139140
} catch {

0 commit comments

Comments
 (0)