Skip to content

feat(node): Wire up SentryTracerProvider#21680

Open
andreiborza wants to merge 3 commits into
ab/sentry-trace-provider-otelfrom
ab/sentry-trace-provider-node
Open

feat(node): Wire up SentryTracerProvider#21680
andreiborza wants to merge 3 commits into
ab/sentry-trace-provider-otelfrom
ab/sentry-trace-provider-node

Conversation

@andreiborza

@andreiborza andreiborza commented Jun 22, 2026

Copy link
Copy Markdown
Member

Wires up the node SDK to use SentryTracerProvider when _experiments.useSentryTracerProvider is enabled (default opt-in).

When enabled, it uses our SentryTracerProvider and async context strategy instead of the Otel SDK's.

For simplicity, a flag is used, but we could change this to be an explicit call (+ a flag to opt out of the current tracer provider) to save some bundle size.

@andreiborza andreiborza requested a review from a team as a code owner June 22, 2026 09:35
@andreiborza andreiborza requested review from JPeer264 and mydea and removed request for a team June 22, 2026 09:35
@nicohrubec nicohrubec self-requested a review June 22, 2026 09:46
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.47 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.95 kB -0.03% -10 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.71 kB -0.02% -9 B 🔽
@sentry/browser (incl. Tracing, Profiling) 50.74 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay) 85.17 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.76 kB -0.01% -7 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 89.86 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 102.52 kB -0.01% -8 B 🔽
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.27 kB -0.03% -11 B 🔽
@sentry/vue 32.62 kB -0.03% -8 B 🔽
@sentry/vue (incl. Tracing) 47.83 kB -0.02% -8 B 🔽
@sentry/svelte 27.5 kB - -
CDN Bundle 29.86 kB - -
CDN Bundle (incl. Tracing) 47.88 kB -0.02% -7 B 🔽
CDN Bundle (incl. Logs, Metrics) 31.42 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.21 kB -0.02% -5 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 70.72 kB - -
CDN Bundle (incl. Tracing, Replay) 85.23 kB -0.01% -5 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.5 kB -0.01% -7 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 91.07 kB -0.01% -6 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.33 kB -0.01% -4 B 🔽
CDN Bundle - uncompressed 88.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.93 kB +0.02% +16 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.55 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.9 kB +0.02% +16 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.37 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 263.8 kB +0.01% +16 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 267.76 kB +0.01% +16 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.5 kB +0.01% +16 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.45 kB +0.01% +16 B 🔺
@sentry/nextjs (client) 50.66 kB -0.02% -6 B 🔽
@sentry/sveltekit (client) 46.36 kB -0.01% -4 B 🔽
@sentry/core/server 76.31 kB +0.02% +10 B 🔺
@sentry/core/browser 63.46 kB +0.03% +18 B 🔺
@sentry/node-core 61.68 kB +0.08% +48 B 🔺
@sentry/node 124.46 kB +0.69% +845 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.55 kB -0.01% -3 B 🔽
@sentry/node - without tracing 74.41 kB +0.97% +714 B 🔺
@sentry/aws-serverless 85.66 kB +0.91% +765 B 🔺
@sentry/cloudflare (withSentry) - minified 175.75 kB +0.03% +49 B 🔺
@sentry/cloudflare (withSentry) 437.99 kB +0.04% +145 B 🔺

View base workflow run

@andreiborza andreiborza changed the title feat(node): Wire up _experiments.useSentryTracerProvider feat(node): Wire up SentryTracerProvider Jun 22, 2026
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from e05567e to dc3cd9d Compare June 22, 2026 11:32
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-otel branch from 7f2f88d to 172dd9f Compare June 22, 2026 11:49
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from dc3cd9d to f3c0c65 Compare June 22, 2026 11:49
Comment thread packages/node/src/sdk/initOtel.ts
coreDebug.warn(
'Could not register SentryTracerProvider because another OpenTelemetry tracer provider is already registered.',
);
return [undefined, undefined];

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.

m: is this in a good state if the setup fails here? we won't install the sentry propagator and context manager in here and then we also bail early in the main setupOtel method but we already set up the otel async context strategy. might be fine just checking

): [BasicTracerProvider, AsyncLocalStorageLookup] {
): [OpenTelemetryTraceProvider | undefined, AsyncLocalStorageLookup | undefined] {
if (client.getOptions()._experiments?.useSentryTracerProvider) {
setOpenTelemetryContextAsyncContextStrategy();

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.

m: do we even need to call this here? setupOtel is called from initOpenTelemetry, which is called in the node init after we make the node-core init which also makes this same call:

setOpenTelemetryContextAsyncContextStrategy();

@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-otel branch from 172dd9f to afb77ef Compare June 22, 2026 18:20
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from e200c8f to 502dca9 Compare June 22, 2026 18:20
Comment thread packages/node/src/sdk/initOtel.ts
Comment thread packages/node/src/sdk/initOtel.ts
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-otel branch from afb77ef to fcdf2df Compare June 22, 2026 18:30
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from 502dca9 to 6ae8302 Compare June 22, 2026 18:30
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-otel branch from fcdf2df to 40d8abc Compare June 22, 2026 18:33
andreiborza and others added 3 commits June 22, 2026 20:46
Add the SentryTracerProvider under an experimental `useSentryTracerProvider`
flag and update the node setup path to register the new TracerProvider and its
async context strategy instead of the full OTel SDK tracer provider when
enabled.
Lift `http.response.status_code` into the top-level `response` context inside the
HTTP server-spans integration's `processEvent`, where the value is already read
for status-code filtering. This covers transactions produced by the
`SentryTracerProvider` (which bypasses the OTel SDK span exporter), so the
provider's `preprocessEvent` hook no longer needs to set it.

The OTel SDK span exporter keeps setting the same value on its path; both derive
the status code from the same span attribute, so the duplicate write is a
harmless idempotent overwrite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-otel branch from 2c670f3 to 308e560 Compare June 22, 2026 18:46
@andreiborza andreiborza force-pushed the ab/sentry-trace-provider-node branch from 6ae8302 to e2f91c0 Compare June 22, 2026 18:46

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 e2f91c0. Configure here.


setGlobalSpy.mockRestore();
setIsSetupSpy.mockRestore();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SentryTracerProvider tests skip OTel teardown

Medium Severity

New OpenTelemetry tests register SentryTracerProvider, but shared afterEach cleanup only shuts down BasicTracerProvider. Global tracer state can leak between tests and make later init calls fail or behave inconsistently.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit e2f91c0. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants