Attach a process-wide session id to every telemetry capture - #412
Merged
Conversation
Product and future AI observability events need to group into one PostHog session per process. Generate the session id once at module load and attach it to every capture() payload's common properties, alongside the existing installation-UUID distinct_id, so nothing downstream has to thread a session identifier through call sites.
The prior test called createTelemetry() twice but asserted against getSessionId(), which never reads from a Telemetry instance — it would have passed even if createTelemetry() were never called. The replacement drives the actual toggle.ts enable/disable/enable cycle and asserts session_id stays constant across the captured payloads.
Callers reading the privacy section need to know session_id is a fresh in-memory UUID per process run, never persisted, so it cannot be used to correlate events across separate CLI launches.
This was referenced Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
capture()call now attaches a process-scopedsession_id(generated once viarandomUUID()at module load) alongside the existing installation-UUIDdistinct_id, so PostHog can group a process's product and future AI/feedback events into one session.getSessionId()so future emitters (AI turn events from CL-5723, feedback from CL-5722) can attach the same session id without re-threading it.distinct_idresolution, the property allowlist discipline, or the held-cli_start-until-consent first-run flow.Test plan
bun run test(via shared lock script)bun run typecheck(pre-existing vendor/node_modules type mismatches unrelated to this change, no telemetry errors)bun run buildsession_idacross multiple captures in one process, stable across separatecreateTelemetry()instances in the same processLinear: CL-5727