Skip to content

Commit 5520f94

Browse files
betegonclaude
andcommitted
fix(telemetry): guard cli.invocation metric against double-emit on retry
initSentry is called again when auto-login or seer-trial middleware retries the command. Without a guard the metric fires twice for one user invocation, inflating counts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 73763c1 commit 5520f94

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lib/telemetry.ts

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

252+
/** Whether the cli.invocation metric has already been emitted this process */
253+
let invocationCounted = false;
254+
252255
/** Match all SaaS regional URLs (us.sentry.io, de.sentry.io, o1234.ingest.us.sentry.io, etc.) */
253256
const SENTRY_SAAS_SUBDOMAIN_RE = /^https:\/\/[^/]*\.sentry\.io(\/|$)/;
254257

@@ -342,10 +345,14 @@ export function initSentry(enabled: boolean): Sentry.BunClient | undefined {
342345
// Tag whether targeting self-hosted Sentry (not SaaS)
343346
Sentry.setTag("is_self_hosted", !isSentrySaasUrl(getSentryBaseUrl()));
344347

345-
// Track TTY vs non-TTY invocations to measure agent/CI usage percentage
346-
Sentry.metrics.count("cli.invocation", 1, {
347-
attributes: { is_tty: !!process.stdout.isTTY },
348-
});
348+
// Track TTY vs non-TTY invocations to measure agent/CI usage percentage.
349+
// Guarded because initSentry is called again on auto-login retry.
350+
if (!invocationCounted) {
351+
invocationCounted = true;
352+
Sentry.metrics.count("cli.invocation", 1, {
353+
attributes: { is_tty: !!process.stdout.isTTY },
354+
});
355+
}
349356

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

0 commit comments

Comments
 (0)