feat(api-client): emit X-DevHelm-Surface telemetry headers#25
Merged
Conversation
Adds CLI surface identification to every authenticated API call so the GTM rollup can attribute usage to the CLI vs. SDKs / MCP / Terraform. Wire contract docs at https://devhelm.io/telemetry; matching API-side handler in mono#332. Headers emitted by default (every request): - X-DevHelm-Surface: cli - X-DevHelm-Surface-Version: package.json version (read at module load via createRequire — no release-script edit needed) - X-DevHelm-Cli-Os: <platform>-<arch> (e.g. darwin-arm64) - X-DevHelm-Cli-Install-Source: npm | brew | other - DEVHELM_INSTALL_SOURCE env var overrides (set this in the brew formula or any other distribution channel that knows better than the heuristics) - Heuristic checks the realpath of process.argv[1] for /Cellar/, /opt/homebrew/, /home/linuxbrew/ → "brew"; /node_modules/ → "npm"; falls back to "other" rather than guessing wrong Opt-out is a single env var, not per-command flag: DEVHELM_TELEMETRY=0 returns an empty headers object and the API receives no surface signal at all. Auth + tenant headers are unaffected. Strict equality on "0" so DEVHELM_TELEMETRY=on / true / yes don't accidentally read as opt-out. Zero callsite changes — `createApiClient` is the single bottleneck for every CLI command, so spreading the headers in there covers all 73 commands without touching one of them. The telemetry module (lib/surface-telemetry.ts) is a pure function of process.* with no external state. Tests: 6 new tests in test/lib/surface-telemetry.test.ts covering defaults, OS detection, install-source override, env opt-out, and the strict-on-"0" parsing. Full suite (899) green; eslint + tsc clean. Bumped to 0.6.3 (additive feature; patch bump because no public CLI surface changed). Co-authored-by: Cursor <cursoragent@cursor.com>
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
Reports the CLI's identity to the DevHelm API on every authenticated request so the GTM rollup can attribute usage to the CLI vs. SDKs / MCP / Terraform. Wire contract documented at https://devhelm.io/telemetry; the matching API-side handler shipped in `devhelmhq/mono#332`.
What lands on the wire (defaults)
Install source detection (in order):
Opt-out
`DEVHELM_TELEMETRY=0` returns an empty headers object — the API receives no surface signal at all. Single env var, not per-command flag. Auth + tenant headers are unaffected. Strict equality on `"0"` (so `DEVHELM_TELEMETRY=on` / `true` / `yes` don't accidentally read as opt-out).
Zero callsite changes
`createApiClient` is the single bottleneck for every CLI command, so spreading the headers there covers all 73 commands without touching one of them. The telemetry module (`lib/surface-telemetry.ts`) is a pure function of `process.*` with no external state.
Tests
Version bumped to `0.6.3` (additive feature; patch bump because no public CLI surface changed).
Test plan
Made with Cursor