Skip to content

Add anonymous usage telemetry via Segment#357

Draft
schurchleycci wants to merge 3 commits into
mainfrom
add-telemetry
Draft

Add anonymous usage telemetry via Segment#357
schurchleycci wants to merge 3 commits into
mainfrom
add-telemetry

Conversation

@schurchleycci
Copy link
Copy Markdown
Contributor

@schurchleycci schurchleycci commented May 22, 2026

Summary

Adds anonymous usage telemetry to chunk via Segment. All events are opt-out and no PII is collected.

Events

`command_invocation`

Fired after every CLI command completes.

Property Value Notes
`anonymous_id` stable UUID Generated on first run, persisted to `~/.config/chunk/config.json`
`sender` `chunk-cli` CCI standard: origin of the event
`team_name` `factory` CCI standard: team responsible
`action` `invoked` CCI standard: user action
`organization_id` CircleCI org ID Included when `CIRCLECI_ORG_ID` is set; omitted otherwise
`command` e.g. `chunk build-prompt` Full command path; never includes flag values
`flags` e.g. `model,output` Sorted comma-separated list of flag names that were explicitly set; no values
`success` `true` / `false` Whether the command exited without error

`identify` (one-time)

Fired once on first run when the `instanceID` UUID is generated. Associates the device with the anonymous ID for Segment/Amplitude. No additional properties beyond the `anonymous_id`.

What is NOT collected

  • Flag values, argument values, file or directory names
  • IP addresses, hostnames, or any network identifiers
  • Tokens, API keys, or any credentials
  • Error messages or stack traces
  • Any personally identifiable information

Opt-out

Telemetry is automatically disabled in any of these conditions:

  • --no-telemetry flag on any command
  • CHUNK_NO_TELEMETRY=1 environment variable
  • NO_ANALYTICS environment variable set
  • DO_NOT_TRACK environment variable set
  • CI environment variable set (all CI systems)
  • noTelemetry: true in ~/.config/chunk/config.json
  • Build-time Segment write key not injected (all local/dev builds are always no-op)

Implementation

  • New internal/telemetry package with three modes: ModeSend (production), ModeNOOP (disabled), ModeLog (debug/stderr)
  • Segment write key injected at build time via -ldflags in .goreleaser.yaml; empty key = no-op, so no events are ever sent from development builds
  • instanceID UUID persisted in ~/.config/chunk/config.json on first run
  • All subcommands instrumented automatically via recordTelemetryForSubcommands in root command setup
  • 500ms flush timeout on Close prevents a slow Segment endpoint from stalling the CLI

Test plan

  • task test passes
  • task lint passes
  • Set CHUNK_TELEMETRY_LOG=1 (ModeLog) and verify [telemetry] track command_invocation on stderr with correct properties
  • Set CHUNK_NO_TELEMETRY=1 and confirm no events are emitted

🤖 Generated with Claude Code

schurchleycci and others added 3 commits May 22, 2026 15:29
Instruments all commands with a Segment-backed telemetry client that
records which command ran, which flags were set, and whether it succeeded.
No arguments, flag values, file paths, or PII are collected.

Implementation:
- internal/telemetry: Segment client with Mode enum (NOOP/Send/Log),
  noop and logging backends, never returns a nil client
- Delegation pattern: a lazily-populated delegatingTelemetry is created
  at startup; PersistentPreRunE resolves the mode and sets the real client,
  then recordTelemetryForSubcommands wraps each RunE without needing
  per-command changes
- Opt-out: --no-telemetry flag, CHUNK_NO_TELEMETRY / NO_ANALYTICS /
  DO_NOT_TRACK / CI env vars, and NoTelemetry field in user config all
  switch the client to ModeNOOP
- Instance ID: a stable UUID is generated on first run and stored in
  ~/.config/chunk/config.json; used as the anonymous device identifier
- Build: Segment write key injected at release time via -ldflags

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds sender, team_name, action, and organization_id (when available via
CIRCLECI_ORG_ID) to every track event to meet CCI Segment standards.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
go mod tidy moves pflag from indirect to direct since it's now
explicitly imported by the telemetry code via cobra's flag types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@schurchleycci schurchleycci marked this pull request as draft May 22, 2026 21:19
@z00b
Copy link
Copy Markdown
Contributor

z00b commented May 28, 2026

@schurchleycci is there a reason this is still in draft?

@schurchleycci
Copy link
Copy Markdown
Contributor Author

@schurchleycci is there a reason this is still in draft?

Yeah, I'm waiting to hear back from the data team on how they want to handle Segment / event tracking generally for chunk CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants