feat: add PostHog event tracking for CLI installs and upgrades (ENG-2277)#293
Open
devin-ai-integration[bot] wants to merge 5 commits into
Open
feat: add PostHog event tracking for CLI installs and upgrades (ENG-2277)#293devin-ai-integration[bot] wants to merge 5 commits into
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
- Add lightweight PostHog client (cli/core/posthog.go) using raw net/http - Track 'Installed CLI' event on first run of each new version - Track 'Upgraded CLI' event with old/new versions after successful upgrade - Deduplicate events via ~/.blaxel/telemetry.json - Inject PostHog API key at build time via ldflags - Fire-and-forget async HTTP POST, non-blocking ENG-2277 Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…detection, comment fix - Use conditional template in .goreleaser.yaml so POSTHOG_KEY env var is optional - Clarify detectInstalledVersion re-resolves symlinks for brew upgrades - Fix misleading comment on getDistinctID (UUID only, no email) Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
On macOS, os.Executable() returns the already-resolved cellar path, so EvalSymlinks cannot follow the updated symlink after brew upgrade. Using exec.LookPath finds the binary by name in PATH, which resolves through the updated /usr/local/bin symlink to the new cellar entry. Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
…erve unknown telemetry fields Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
…ss on os.Exit Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
Contributor
There was a problem hiding this comment.
LGTM
All previous comments are resolved. The final commit correctly adds FlushPosthog() to ExitWithError, ExitWithMessage, and Exit — since os.Exit skips deferred calls, these explicit flushes are necessary and correct. Ready to merge.
Tag @mendral-app with feedback or questions. View session
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
Adds lightweight PostHog event tracking to the CLI with no new dependencies — uses only
net/httpandcrypto/randfrom stdlib. Mirrors the existing Sentry integration pattern (build-time key injection, opt-in consent viaIsTrackingEnabled()).Two events are tracked:
~/.blaxel/telemetry.jsonbl upgradewithold_versionandnew_versionpropertiesEvents are fire-and-forget (async goroutine, 5s timeout). The PostHog API key is injected at build time via ldflags, same as
sentryDSN.Files changed:
cli/core/posthog.go(new) — PostHog client, telemetry state persistence, UUID generation, deduplication logicmain.go— addsposthogKeyldflag var, initializes PostHog when tracking is enabledcli/core/root.go— callsTrackCLIInstalled(version)inExecute()cli/upgrade.go— captures old version, detects new version post-upgrade, firesTrackCLIUpgraded.goreleaser.yaml/Makefile/.github/workflows/release.yaml— build-time key injectionReview & Testing Checklist for Human
POSTHOG_KEYGitHub secret must be created before the next release. Verify that GoReleaser doesn't fail whenPOSTHOG_KEYenv var is unset/empty (it may need to be set to""likeSENTRY_DSN).detectInstalledVersion()output parsing — the version command usescore.Print/core.PrintInfowhich may emit ANSI color codes. Verify that parsing"Version: X.Y.Z"works correctly when the new binary's stdout is not a TTY (piped throughexec.Command(...).Output()).FlushPosthog()usestime.Sleep(500ms)instead of async.WaitGroup— events could be silently dropped if the HTTP POST takes longer. Acceptable trade-off? Consider if a WaitGroup approach would be better.loadTelemetryStateusessync.Once— telemetry state is loaded once per process. This is fine for normal CLI usage but means the state won't be re-read within a single process lifetime (relevant for upgrade flow whereTrackCLIUpgradedthen updates state).POSTHOG_KEY=phc_test make build-dev, runbl versiontwice, verify~/.blaxel/telemetry.jsonis created with correct structure, and that only one "Installed CLI" event would fire.Notes
posthog.go— the code is intentionally minimal and mirrors the untested Sentry client pattern in this repo.getDistinctID()comment mentions "workspace email" but the implementation only uses a persisted anonymous UUID. The comment should be updated or the email lookup added if that's desired.SDKsfield intelemetryStateis forward-looking — it's unused by the CLI but will be used by the SDK repos (sharing the same~/.blaxel/telemetry.jsonfile).ENG-2277
Link to Devin session: https://app.devin.ai/sessions/43a6073c1fe54dbfb87b42e3dc01db56
Requested by: @Grotoma
Note
Adds lightweight PostHog event tracking to the CLI using only stdlib (
net/http,crypto/rand). Tracks "Installed CLI" once per new version (deduplicated via~/.blaxel/telemetry.json) and "Upgraded CLI" after a successfulbl upgrade. Mirrors the existing Sentry integration pattern with build-time key injection and opt-in viaIsTrackingEnabled().Written by Mendral for commit 9e1da84.