Skip to content

fix(cli): Move the CLI to Sentry SDK v11 and its defaults - #1694

Merged
BYK merged 7 commits into
mainfrom
fix/cli-vercel-sigterm-listener-leak
Oct 28, 2026
Merged

BYK merged 7 commits into
mainfrom
fix/cli-vercel-sigterm-listener-leak

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

When VERCEL is set, v10's @sentry/node-core/light init() adds a SIGTERM flush listener on every init and never removes it. Library-mode commands (createSentrySDK) call initSentry() per command, so in-process callers like @sentry/bundler-plugins hit MaxListenersExceededWarning during Vercel builds. v11 registers that listener once (getsentry/sentry-javascript#25146), and the rest of toolkit is already on v11, so the CLI now uses the workspace catalog @sentry/core and @sentry/node (11.6.0). The local @sentry/node-core and @sentry/core patches are gone.

SDK defaults. The CLI now uses v11 defaults rather than recreating v10 behavior:

  • CLI mode uses Sentry.init() defaults, including dataCollection and attachStacktrace. The bundle didn't grow, because the bundled MCP code already pulled in v11's integrations.
  • The SDK's Http/NodeFetch integrations now create the http.client spans and inject sentry-trace/baggage. The CLI's own HTTP spans and manual header injection existed only because Bun's fetch didn't fire undici diagnostics channels, and the CLI now runs on Node. Response-cache hits are no longer wrapped in an http.client span, so span.op:http.client counts only requests that went out. Cache telemetry is unchanged: the response cache still emits cache.get/cache.put spans and the cache.hit_rate metric. Retries now show one span per attempt.
  • Library mode uses getDefaultIntegrationsWithoutPerformance() and leaves out integrations that hook the host process or its diagnostics channels (process handlers, HTTP/fetch, child process, worker threads, framework error handlers). Without those integrations, and on Bun (whose fetch doesn't fire undici diagnostics channels), the API client still creates its own http.client span and adds sentry-trace/baggage, so in-process callers keep request tracing.
  • Runtime channel injection is stripped at build time with the SDK's __SENTRY_CHANNEL_INJECTION__ define, which is what the bundler plugins' excludeChannelInjection sets. That makes index.cjs ~72 KB smaller. enableRuntimeChannelInjection: false stays so unbundled dev and test runs behave the same.
  • unknown_command and invalid_argument are sent with captureEvent instead of captureMessage. With attachStacktrace on, captureMessage adds a synthetic exception, which marks the session errored.

Kept on purpose:

  • traceLifecycle: "static", because dashboards rely on scope tags on transactions and beforeSendTransaction scrubs server_name; both are dropped under v11's default span streaming. Moving to streamed spans should be its own change.
  • v11 removed enableLogs, so library mode drops logs via beforeSendLog instead.

Two v11 issues fixed here:

  • v11 attaches the client to the current scope before switching to the AsyncLocalStorage context strategy. When initSentry() runs inside a still-pending pre-init span, as it does in the CLI's middleware chain, the client is lost, so commands like sentry org list sent no telemetry at all. initSentry() now re-binds the client after init.
  • attachSentryReporter() used a runtime require() that the bundler leaves unresolved, so shipped builds either failed it silently or, in library mode, could load the host app's @sentry/node. It's now a static import, which means shipped builds now forward consola logs, which they never did on v10.

Repeated initSentry() calls with VERCEL=1 keep one SIGTERM listener.

Fixes #1692

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Oct 28, 2026 9:02pm UTC

Request Review

@sentry-junior sentry-junior Bot added the CLI Sentry CLI and CLI documentation label Oct 28, 2026
Comment thread packages/cli/src/lib/telemetry.ts Outdated
@BYK
BYK marked this pull request as ready for review October 28, 2026 14:05

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, maybe we should just patch the Sentry Node SDK and then submit a bug and a PR to it instead?

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why are we not on v11 of the SDK? Does it also have the same problem?

@sentry-junior sentry-junior Bot changed the title fix(cli): Drop stale SDK SIGTERM listeners on telemetry re-init fix(cli): Move the CLI to the catalog Sentry SDK (v11) Oct 28, 2026
@github-actions github-actions Bot removed the risk: medium PR risk score: medium label Oct 28, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/cli/src/lib/telemetry.ts Outdated
Comment thread packages/cli/src/lib/telemetry.ts Outdated
Comment thread packages/cli/src/lib/telemetry.ts Outdated
Comment thread packages/cli/src/lib/telemetry.ts Outdated
Comment thread packages/cli/src/lib/telemetry.ts
Comment thread packages/cli/src/lib/telemetry.ts Outdated
Comment thread packages/cli/src/cli.ts Outdated
Comment thread packages/cli/test/lib/telemetry.test.ts Outdated
@sentry-junior sentry-junior Bot changed the title fix(cli): Move the CLI to the catalog Sentry SDK (v11) fix(cli): Move the CLI to Sentry SDK v11 and its defaults Oct 28, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 99eb7f4. Configure here.

Comment thread packages/cli/src/lib/sentry-client.ts

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but please address my earlier comments.

Also, we have some merge conflicts that needs to be resolved.

sentry-junior Bot and others added 6 commits October 28, 2026 20:38
Under VERCEL the bundled light SDK registers a SIGTERM flush handler on
every Sentry.init() and never removes it. Library-mode commands re-init
per invocation, so in-process callers like the bundler plugins leak one
listener per command and hit MaxListenersExceededWarning after 10.

Track the listeners each init adds and remove them before the next init,
keeping only the current client's flush handler.

Fixes #1692
Move the fix from a telemetry.ts workaround into the existing
@sentry/node-core patch. The light init() now registers one SIGTERM
listener that flushes the latest client, mirroring
getsentry/sentry-javascript#25146 for @sentry/node.
The CLI pinned @sentry/core, @sentry/node and @sentry/node-core on v10,
and v10's light init() adds a SIGTERM listener per init under Vercel.
v11 already registers that listener once, so switch the CLI to the
workspace catalog versions and drop the v10 patches.

v11 removes @sentry/node-core/light, so the CLI now inits @sentry/node
without its default integrations and passes the v10 light set
explicitly. Other v11 defaults are pinned back to v10 behavior:
static traces, the v10 data collection baseline, no attached stack
traces, no runtime channel injection, and no logs in library mode.

Also binds the client after init, because v11 loses it when init runs
inside a pending span, and imports the consola reporter statically so
the bundle no longer requires a runtime @sentry/node.
Address review feedback on the v11 migration:

- Use Sentry.init() defaults instead of a hand-maintained integration
  list; library mode uses the no-performance defaults and filters out
  integrations that hook the host process or its diagnostics channels.
- Drop the v10 dataCollection baseline and attachStacktrace override.
- Send informational unknown_command/invalid_argument events through
  captureEvent so attachStacktrace doesn't mark sessions errored.
- Remove the VERCEL SIGTERM tests now that the SDK registers it once.
- Fix stale Bun-binary comments and drop stale load-time figures.
- Drop the CLI's own http.client spans (API client, OAuth) and manual
  sentry-trace/baggage injection. They existed because Bun's fetch
  didn't fire undici diagnostics channels; the CLI now runs on Node,
  so the SDK's Http/NodeFetch integrations cover both.
- Set the SDK's __SENTRY_CHANNEL_INJECTION__ build define to false so
  esbuild tree-shakes the runtime module hooks from shipped bundles.

Co-Authored-By: Burak Yigit Kaya <126780+BYK@users.noreply.github.com>
Library mode excludes the SDK's Http/NodeFetch integrations so it doesn't
trace the host's traffic, and Bun's fetch doesn't fire the undici channels
they use. In those cases the API client adds its own http.client span and
sentry-trace/baggage headers again; Node CLI runs keep relying on the SDK.
@sentry-junior
sentry-junior Bot force-pushed the fix/cli-vercel-sigterm-listener-leak branch from 99eb7f4 to 8911ed3 Compare October 28, 2026 20:59
Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
@BYK
BYK enabled auto-merge (squash) October 28, 2026 21:04
@BYK
BYK merged commit 69eb255 into main Oct 28, 2026
40 of 43 checks passed
@BYK
BYK deleted the fix/cli-vercel-sigterm-listener-leak branch October 28, 2026 21:13
Comment on lines +645 to +648
activeSpanOp = span
? spanToJSON(span).attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP]
: undefined;
return jsonResponse({ ok: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing tests read the operation from nonexistent SpanJSON.attributes

spanToJSON() exposes the operation as top-level op and span attributes under data, so tracedRequest() records undefined and both tracing tests fail. This breaks the CLI unit-test run.

Evidence
  • @sentry/core v11's SpanJSON shape uses top-level op and data; it has no attributes property.
  • tracedRequest() reads spanToJSON(span).attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP], which evaluates to undefined even when a span is active.
  • The library-mode and CLI-mode tests assert activeSpanOp is "http.client" and "test"; the package's test:unit script runs test/lib, so these assertions fail in that run.

Identified by Warden · code-review · ARY-TQS

sentry-junior Bot added a commit that referenced this pull request Oct 28, 2026
#1694 made the authenticated fetch return early when manual HTTP tracing
is off (the default Node CLI), and merging it left the completion seed
chained only on the traced branch, so the normal CLI never filled
completion_cache. Seed after either branch, from one call site.

This is also what failed "remembers the issue for shell completion" in
CI, which tests the PR merged with main.
sentry-junior Bot added a commit that referenced this pull request Oct 28, 2026
Leave main's tracing code in createAuthenticatedFetch untouched and seed
completions around the whole fetch instead, so this PR's change to
sentry-client.ts is one wrapper rather than a rewrite of the
isManualHttpTracing() branches that #1694 added.

This branch was previously deployed

1 inactive deployment
Preview — 17dcf630 Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI Sentry CLI and CLI documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sentry 0.45.0 library commands retain SIGTERM listeners under VERCEL

1 participant