Repository navigation
fix(cli): Move the CLI to Sentry SDK v11 and its defaults - #1694
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
left a comment
There was a problem hiding this comment.
Actually, maybe we should just patch the Sentry Node SDK and then submit a bug and a PR to it instead?
BYK
left a comment
There was a problem hiding this comment.
Wait, why are we not on v11 of the SDK? Does it also have the same problem?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
BYK
left a comment
There was a problem hiding this comment.
Looks good but please address my earlier comments.
Also, we have some merge conflicts that needs to be resolved.
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.
99eb7f4 to
8911ed3
Compare
Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
| activeSpanOp = span | ||
| ? spanToJSON(span).attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP] | ||
| : undefined; | ||
| return jsonResponse({ ok: true }); |
There was a problem hiding this comment.
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/corev11'sSpanJSONshape uses top-levelopanddata; it has noattributesproperty.tracedRequest()readsspanToJSON(span).attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP], which evaluates toundefinedeven when a span is active.- The library-mode and CLI-mode tests assert
activeSpanOpis"http.client"and"test"; the package'stest:unitscript runstest/lib, so these assertions fail in that run.
Identified by Warden · code-review · ARY-TQS
#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.
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.

When
VERCELis set, v10's@sentry/node-core/lightinit()adds aSIGTERMflush listener on every init and never removes it. Library-mode commands (createSentrySDK) callinitSentry()per command, so in-process callers like@sentry/bundler-pluginshitMaxListenersExceededWarningduring 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/coreand@sentry/node(11.6.0). The local@sentry/node-coreand@sentry/corepatches are gone.SDK defaults. The CLI now uses v11 defaults rather than recreating v10 behavior:
Sentry.init()defaults, includingdataCollectionandattachStacktrace. The bundle didn't grow, because the bundled MCP code already pulled in v11's integrations.http.clientspans and injectsentry-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 anhttp.clientspan, sospan.op:http.clientcounts only requests that went out. Cache telemetry is unchanged: the response cache still emitscache.get/cache.putspans and thecache.hit_ratemetric. Retries now show one span per attempt.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 ownhttp.clientspan and addssentry-trace/baggage, so in-process callers keep request tracing.__SENTRY_CHANNEL_INJECTION__define, which is what the bundler plugins'excludeChannelInjectionsets. That makesindex.cjs~72 KB smaller.enableRuntimeChannelInjection: falsestays so unbundled dev and test runs behave the same.unknown_commandandinvalid_argumentare sent withcaptureEventinstead ofcaptureMessage. WithattachStacktraceon,captureMessageadds a synthetic exception, which marks the session errored.Kept on purpose:
traceLifecycle: "static", because dashboards rely on scope tags on transactions andbeforeSendTransactionscrubsserver_name; both are dropped under v11's default span streaming. Moving to streamed spans should be its own change.enableLogs, so library mode drops logs viabeforeSendLoginstead.Two v11 issues fixed here:
initSentry()runs inside a still-pending pre-init span, as it does in the CLI's middleware chain, the client is lost, so commands likesentry org listsent no telemetry at all.initSentry()now re-binds the client after init.attachSentryReporter()used a runtimerequire()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 withVERCEL=1keep oneSIGTERMlistener.Fixes #1692
--
View Junior Session [Sentry]