Skip to content

Commit 888863f

Browse files
Stamp PostHog app version on every telemetry event (#444)
PostHog Version breakdown reads the standard app version property. Events only sent a custom service_version, so every release bucketed as Other. Dual-stamp the package version so the built-in filter works and existing dashboards keep working.
1 parent a5150bf commit 888863f

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

docs/TELEMETRY.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ there is nothing to compact — an event that also fires on no-ops makes its own
3333
duration and turn-count averages meaningless.
3434

3535
Common properties attached to every event: a random installation UUID
36-
(`distinct_id`), `session_id`, `service_version`, `os_type`, `os_arch`, and a
36+
(`distinct_id`), `session_id`, `$app_version` (PostHog's standard Version
37+
property, the running package version), `service_version` (same value, kept
38+
for existing custom-property dashboards), `os_type`, `os_arch`, and a
3739
`schema_version` for forward compatibility.
3840

3941
Approximate country-level location is derived server-side by PostHog from the

src/telemetry/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export function getSessionId(): string {
9191

9292
// Per-event property allowlist. Anything not listed here is stripped before
9393
// the payload leaves the process. Together with the fixed common properties
94-
// capture() appends (service_version, os_type, os_arch, schema_version,
95-
// session_id), this bounds everything telemetry can ever contain.
94+
// capture() appends ($app_version, service_version, os_type, os_arch,
95+
// schema_version, session_id), this bounds everything telemetry can ever contain.
9696
const EVENT_PROPERTY_ALLOWLIST: Record<TelemetryEvent, readonly string[]> = {
9797
cli_start: [],
9898
session_end: ["status", "turn_count", "duration_ms", "session_mode", "exit_reason"],
@@ -353,6 +353,10 @@ export function createTelemetry(options: CreateTelemetryOptions): Telemetry {
353353
timestamp: new Date().toISOString(),
354354
properties: {
355355
...allowedProperties(event, properties),
356+
// PostHog's built-in Version breakdown reads $app_version; without it
357+
// every event buckets as "Other". service_version is the same value
358+
// kept for dashboards that already filter on the custom property.
359+
$app_version: pkg.version,
356360
service_version: pkg.version,
357361
os_type: process.platform,
358362
os_arch: process.arch,

tests/unit/telemetry.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ test("capture payload shape includes distinct_id and common props, with no clien
259259
expect(body.properties.$geoip_disable).toBeUndefined();
260260
expect(body.properties.schema_version).toBe(1);
261261
expect(typeof body.properties.service_version).toBe("string");
262+
expect(body.properties.$app_version).toBe(body.properties.service_version);
263+
expect(typeof body.properties.$app_version).toBe("string");
264+
expect(String(body.properties.$app_version).length).toBeGreaterThan(0);
262265
expect(body.properties.os_type).toBe(process.platform);
263266
expect(body.properties.os_arch).toBe(process.arch);
264267
});

0 commit comments

Comments
 (0)