Skip to content

fix(core): Read external propagation context from the carrier - #23271

Merged
andreiborza merged 9 commits into
developfrom
ab/nextjs-otlp-e2e
Aug 11, 2026
Merged

fix(core): Read external propagation context from the carrier#23271
andreiborza merged 9 commits into
developfrom
ab/nextjs-otlp-e2e

Conversation

@andreiborza

@andreiborza andreiborza commented Aug 11, 2026

Copy link
Copy Markdown
Member

What

otlpIntegration kept its trace context provider in module state, so it was silently ignored whenever a bundler emitted more than one copy of @sentry/core, and errors fell back to a Sentry-generated trace instead of the active OpenTelemetry one.

Also adds a nextjs-otlp e2e app covering that setup, where OpenTelemetry owns tracing and metrics and Sentry captures errors only.

Why

Next.js splits @sentry/core across server chunks, which made trace connection between OpenTelemetry telemetry and Sentry errors fail in exactly the setup the integration exists for.

`otlpIntegration` registered its trace context provider in module state, so it
was silently ignored whenever a bundler emitted more than one copy of
`@sentry/core` (one per Next.js server chunk, for instance). Errors then fell
back to a Sentry-generated trace instead of the active OpenTelemetry one.

Adds a `nextjs-otlp` e2e app covering the setup this broke in: OpenTelemetry
owns tracing and metrics, Sentry captures errors only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@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 fc257da. Configure here.

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.29 kB +0.15% +45 B 🔺
@sentry/browser - with treeshaking flags 28.47 kB +0.15% +40 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 26.8 kB +0.14% +35 B 🔺
@sentry/browser (incl. Tracing) 48.54 kB +0.1% +45 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.56 kB +0.11% +49 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.44 kB +0.1% +49 B 🔺
@sentry/browser (incl. Tracing, Replay) 87.95 kB +0.04% +27 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.36 kB +0.09% +66 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 92.66 kB +0.03% +27 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 105.36 kB +0.05% +50 B 🔺
@sentry/browser (incl. Feedback) 47.61 kB +0.11% +52 B 🔺
@sentry/browser (incl. sendFeedback) 35.11 kB +0.14% +48 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.26 kB +0.12% +48 B 🔺
@sentry/browser (incl. Metrics) 31.28 kB +0.05% +15 B 🔺
@sentry/browser (incl. Logs) 31.53 kB -0.02% -4 B 🔽
@sentry/browser (incl. Metrics & Logs) 32.2 kB +0.03% +7 B 🔺
@sentry/react 32.09 kB +0.12% +38 B 🔺
@sentry/react (incl. Tracing) 50.73 kB +0.13% +63 B 🔺
@sentry/vue 35.34 kB +0.11% +37 B 🔺
@sentry/vue (incl. Tracing) 50.5 kB +0.14% +67 B 🔺
@sentry/svelte 30.31 kB +0.13% +39 B 🔺
CDN Bundle 31.59 kB +0.27% +84 B 🔺
CDN Bundle (incl. Tracing) 48.87 kB +0.16% +78 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.8 kB +0.27% +89 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 50.83 kB +0.17% +86 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.34 kB +0.12% +88 B 🔺
CDN Bundle (incl. Tracing, Replay) 86.46 kB +0.08% +67 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.33 kB +0.05% +43 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 92.17 kB +0.08% +73 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.14 kB +0.07% +61 B 🔺
CDN Bundle - uncompressed 93.77 kB +0.24% +217 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 146.66 kB +0.15% +217 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.17 kB +0.22% +217 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.46 kB +0.15% +217 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.1 kB +0.1% +217 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.92 kB +0.09% +217 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.7 kB +0.08% +217 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.61 kB +0.08% +217 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.38 kB +0.08% +217 B 🔺
@sentry/nextjs (client) 53.29 kB +0.12% +59 B 🔺
@sentry/sveltekit (client) 48.96 kB +0.13% +60 B 🔺
@sentry/core/server 65.44 kB +0.01% +3 B 🔺
@sentry/core/browser 51.8 kB +0.04% +16 B 🔺
@sentry/node 117.98 kB +0.07% +74 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 82.09 kB +0.08% +64 B 🔺
@sentry/aws-serverless 91.5 kB +0.07% +61 B 🔺
@sentry/cloudflare (withSentry) - minified 214.1 kB +0.04% +73 B 🔺
@sentry/cloudflare (withSentry) 528.64 kB +0.01% +27 B 🔺

View base workflow run

@andreiborza
andreiborza marked this pull request as ready for review August 11, 2026 11:27
Comment on lines +4 to +16
const nextConfig: NextConfig = {
// The instrumentation hook and the route handlers must share one copy of each OpenTelemetry
// package, otherwise the providers registered at startup are invisible to the request path.
serverExternalPackages: [
'@opentelemetry/api',
'@opentelemetry/exporter-metrics-otlp-http',
'@opentelemetry/exporter-trace-otlp-http',
'@opentelemetry/resources',
'@opentelemetry/sdk-metrics',
'@opentelemetry/sdk-trace-base',
'@opentelemetry/sdk-trace-node',
],
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@chargome can you validate if this is needed? Does this make sense?

Image

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.

see review

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.

h: The test should cover both Turbopack and webpack (as a variant) - you can check out the other nextjs 16 tests for the setup

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in b602c33

Comment on lines +8 to +14
'@opentelemetry/api',
'@opentelemetry/exporter-metrics-otlp-http',
'@opentelemetry/exporter-trace-otlp-http',
'@opentelemetry/resources',
'@opentelemetry/sdk-metrics',
'@opentelemetry/sdk-trace-base',
'@opentelemetry/sdk-trace-node',

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.

These will basically just receive a require(<packageName>) in the bundled output. So at runtime this looks up node_modules for this package and just use the version declared in package.json.

If you have different versions of this package floating around (through different dependencies) then this is just undefined behaviour at runtime

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.

I don't know if that plays a role in our setup since we also ship '@opentelemetry/api' via the sdk

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably only plays a role if user's @opentelemetry/api differs from what we use in the SDK I guess. I'll take it out for now.

@chargome chargome 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.

@andreiborza
andreiborza merged commit 94be41e into develop Aug 11, 2026
275 checks passed
@andreiborza
andreiborza deleted the ab/nextjs-otlp-e2e branch August 11, 2026 12:59
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.

4 participants