Adds anonymous telemetry by schnie · Pull Request #2009 · astronomer/astro-cli

Add Segment-based telemetry to track CLI usage anonymously. Users can
opt-out via `astro telemetry disable` or ASTRO_TELEMETRY_DISABLED=1.

Features:
- Fire-and-forget pattern using detached subprocess
- Tracks command paths (not arguments/values)
- Detects agent (Claude Code, Cursor) and CI environments
- Anonymous user ID stored in config

Co-Authored-By: Claude <noreply@anthropic.com>

@pre-commit-ci @schnie

@schnie schnie changed the title feat: add anonymous telemetry tracking Adds anonymous telemetry tracking

Feb 20, 2026

@schnie

@schnie

@schnie schnie marked this pull request as ready for review

February 20, 2026 19:51
- Skip PersistentPreRunE chain for _telemetry-send subprocess to avoid
  network I/O, token validation, and recursive telemetry tracking
- Use ordered slices instead of maps in DetectContext to ensure
  deterministic results (generic CI checked last)
- Accept full 2xx range in Send() instead of only 200
- Collect real OS version via uname/ver instead of duplicating GOOS/GOARCH

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Already identified by the top-level source field on the payload.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The value is runtime.GOARCH (cpu architecture), not a platform.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@schnie @claude

- Set SilenceUsage/SilenceErrors at construction time on _telemetry-send
  command instead of inside RunE
- Write minimal config to in-memory fs before InitConfig in tests to
  avoid touching the real filesystem

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@schnie @claude

Replace test-only extractCommandPath/splitCommandPath helpers with
actual cobra commands so the test exercises the production code path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@schnie schnie changed the title Adds anonymous telemetry tracking Adds anonymous telemetry

Feb 23, 2026
- Bound stdin read in _telemetry-send to 64KB via io.LimitReader
- Drain response body before close to allow HTTP connection reuse
- Replace fragile cmd.Name() string match with cobra annotation for
  PersistentPreRunE bypass
- Log subprocess spawn failures in debug mode
- Add one-time first-run notice to stderr informing users about
  telemetry and how to opt out

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Check return value of io.Copy (errcheck)
- Extract magic number to named constant maxStdinBytes (mnd)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>