✨ feat: Add anonymous PostHog telemetry to mb CLI#43
Open
Conversation
Track installs, DAU, and command usage via PostHog with anonymous UUIDs. Opt-out via --disable-telemetry flag or MB_DISABLE_TELEMETRY=1.
- Add 11 Ginkgo tests covering UUID persistence, CI detection, context round-trip, nil receiver safety, and invalid JSON recovery - Add IsCI() to auto-disable telemetry in CI environments - Make all capture methods nil-receiver safe, removing nil guards at call sites - Add WithContext/FromContext helpers matching tapes PR pattern
- Flush telemetry before ExecSSH (process replace skips PostRunE)
- Track actual subcommand via cmd.CommandPath() instead of root cmd.Name()
- Return nil when telemetry disabled (skip PostHog connection and UUID creation)
- Use os.UserHomeDir() at call time instead of os.Getenv("HOME") at init
- Pass actual mixtape name from sandbox response in CaptureUp
- Drop MB_DISABLE_TELEMETRY env var for tapes consistency (use flag + CI detection)
- Add $lib: "mb-cli" property for PostHog source attribution - Extract initTelemetry/closeTelemetry into named functions matching tapes pattern
Move PostHog API key from hardcoded source to build-time ldflag injection, bind disable-telemetry flag through Viper for proper config/flag/env precedence, and thread the key through Dagger build and release pipelines.
Contributor
Author
|
Applied the review feedback from papercomputeco/tapes#149 to align this PR:
|
Pass POSTHOG_API_KEY secret to dagger calls and make apple-build in both release and nightly workflows so production builds have telemetry enabled.
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
pkg/telemetrypackage with UUID persistence (~/.mb/telemetry.json) and PostHog client wrappermb_cli_installed,mb_cli_command_run,mb_cli_sandbox_created,mb_cli_sandbox_stopped,mb_cli_ssh_connected,mb_cli_mixtape_pulled,mb_cli_error--disable-telemetryflag or automatic CI environment detectionDesign decisions
NewPosthogClientreturns nil when disabled, all capture methods are no-ops on nil receiver. No PostHog connection or UUID file created when telemetry is off.CI,GITHUB_ACTIONS,GITLAB_CI,CIRCLECI,TRAVIS,JENKINS_URL,BUILDKITE,CODEBUILD_BUILD_IDCaptureCommandRun(cmd.CommandPath())called in each subcommand'sRunEso events log"mb up","mb ssh"etc. instead of just"mb"telem.Done()called beforessh.ExecSSH()sincesyscall.Execreplaces the process andPersistentPostRunEnever runsos.UserHomeDir()at call time instead ofos.Getenv("HOME")at package init for container robustnessTest plan
go vet ./...cleanmb upand verify event appears in PostHog--disable-telemetryand confirm no events sent~/.mb/telemetry.jsonis created on first run