Skip to content

Commit 8236325

Browse files
betegonclaude
andauthored
refactor(telemetry): convert is_tty metric to span tag (#499)
## Summary Replaces the `cli.invocation` counter metric with a `Sentry.setTag("is_tty", ...)` so the TTY/non-TTY signal lives on every transaction instead of in the separate Metrics dashboard. This lets us filter and group any Discover query by terminal type — correlating it with command, latency, errors, etc. ## Changes - Swap `Sentry.metrics.count("cli.invocation", ...)` for `Sentry.setTag("is_tty", ...)` - Remove the `invocationCounted` guard (tags are idempotent on re-init) ## Test plan - `bun run typecheck` — passes - `bun test test/lib/telemetry.test.ts` — all 96 tests pass - Run `sentry issue list` in a terminal and via pipe, confirm `is_tty` tag appears on transactions in Sentry Discover Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4e62bda commit 8236325

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/lib/telemetry.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ const EXCLUDED_INTEGRATIONS = new Set([
266266
/** Current beforeExit handler, tracked so it can be replaced on re-init */
267267
let currentBeforeExitHandler: (() => void) | null = null;
268268

269-
/** Whether the cli.invocation metric has already been emitted this process */
270-
let invocationCounted = false;
271-
272269
/** Match all SaaS regional URLs (us.sentry.io, de.sentry.io, o1234.ingest.us.sentry.io, etc.) */
273270
const SENTRY_SAAS_SUBDOMAIN_RE = /^https:\/\/[^/]*\.sentry\.io(\/|$)/;
274271

@@ -372,14 +369,8 @@ export function initSentry(
372369
// Tag whether targeting self-hosted Sentry (not SaaS)
373370
Sentry.setTag("is_self_hosted", !isSentrySaasUrl(getSentryBaseUrl()));
374371

375-
// Track TTY vs non-TTY invocations to measure agent/CI usage percentage.
376-
// Guarded because initSentry is called again on auto-login retry.
377-
if (!invocationCounted) {
378-
invocationCounted = true;
379-
Sentry.metrics.count("cli.invocation", 1, {
380-
attributes: { is_tty: !!process.stdout.isTTY },
381-
});
382-
}
372+
// Tag whether running in an interactive terminal or agent/CI environment
373+
Sentry.setTag("is_tty", !!process.stdout.isTTY);
383374

384375
// Wire up consola → Sentry log forwarding now that the client is active
385376
attachSentryReporter();

0 commit comments

Comments
 (0)