-
Notifications
You must be signed in to change notification settings - Fork 125
sends posthog events in a detached mode #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Entire-Checkpoint: 8b12ecd0beb5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors CLI telemetry to be sent via a detached subprocess instead of the main process, avoiding blocking the main command execution while still sending PostHog events when enabled.
Changes:
- Replace the old PostHog client/interface with a detached telemetry pipeline that serializes events to JSON and spawns a separate process to send them.
- Add a hidden
__send_analyticsCobra command that deserializes the payload and sends it via PostHog, and wire it intoNewRootCmd’sPersistentPostRun. - Remove the previous synchronous telemetry implementation and its tests, and add new tests for the detached telemetry code paths and payload serialization.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/entire/cli/telemetry/telemetry.go | Removed the old in-process PostHog client (Client interface, NoOpClient, PostHogClient, NewClient, and TrackCommand/Close) in favor of the new detached telemetry model. |
| cmd/entire/cli/telemetry/telemetry_test.go | Removed tests tied to the old telemetry client types and behaviors (opt-out handling, NoOpClient, and PostHogClient guardrails). |
| cmd/entire/cli/telemetry/detached.go | Introduces the detached telemetry pipeline: EventPayload, TrackCommandDetached (building payload, applying opt-out, and calling spawnDetachedAnalytics), and SendEvent (reconstructing the PostHog client in the subprocess and enqueueing the event). |
| cmd/entire/cli/telemetry/detached_unix.go | Adds a Unix-only implementation of spawnDetachedAnalytics that re-invokes the CLI in a new process group with the __send_analytics command and payload JSON, so analytics sending is fully detached from the parent process. |
| cmd/entire/cli/telemetry/detached_test.go | Adds tests for payload JSON round-tripping, basic guardrails around TrackCommandDetached (nil/hidden commands and opt-out env var), invalid JSON handling in SendEvent, and stringifyArg behavior. |
| cmd/entire/cli/root.go | Switches PersistentPostRun to use TrackCommandDetached when settings enable telemetry, adds a guard to avoid telemetry for the __send_analytics command itself, and registers the hidden __send_analytics command that invokes telemetry.SendEvent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
251a667 to
1f49d68
Compare
1f49d68 to
1e37755
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Entire-Checkpoint: ba59c426c910
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Entire-Checkpoint: e032154c0b18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| // Skip analytics for the analytics command itself (prevents recursion) | ||
| if cmd.Name() == "__send_analytics" { | ||
| return | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant analytics command check with misleading comment
Low Severity
The check cmd.Name() == "__send_analytics" is redundant because TrackCommandDetached already skips hidden commands, and __send_analytics is defined with Hidden: true. The comment states this "prevents recursion" but the actual recursion prevention happens in TrackCommandDetached via the cmd.Hidden check. This creates confusion about where the safeguard actually lives and adds unnecessary code. The only benefit is avoiding a LoadEntireSettings call for the analytics command, but this optimization intent isn't documented.
Avoids blocking the main thread just to send telemetry.
Right now, depending on the region, PostHog may take around 1 second to send events.
If we spin up a new process that sends telemetry in detached mode, we make sure that:
Note
Medium Risk
Changes how CLI telemetry is emitted by spawning a detached process and adding a hidden command entrypoint; failures or platform differences (non-Unix no-op) could lead to missing or duplicated analytics events.
Overview
CLI telemetry is now sent asynchronously by spawning a detached subprocess instead of initializing a PostHog client in-process during
PersistentPostRun.This introduces a hidden
__send_analyticscommand that receives a JSON payload and callstelemetry.SendEvent, plus new telemetry helpers (BuildEventPayload,TrackCommandDetached, and Unix-only detached process spawning) and associated tests; the previous synchronoustelemetry.Clientimplementation and tests are removed.Written by Cursor Bugbot for commit 732e342. This will update automatically on new commits. Configure here.