fix(core): Read external propagation context from the carrier - #23271
Conversation
`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>
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 fc257da. Configure here.
size-limit report 📦
|
| 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', | ||
| ], | ||
| }; |
There was a problem hiding this comment.
@chargome can you validate if this is needed? Does this make sense?
There was a problem hiding this comment.
h: The test should cover both Turbopack and webpack (as a variant) - you can check out the other nextjs 16 tests for the setup
| '@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', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I don't know if that plays a role in our setup since we also ship '@opentelemetry/api' via the sdk
There was a problem hiding this comment.
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.


What
otlpIntegrationkept 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-otlpe2e app covering that setup, where OpenTelemetry owns tracing and metrics and Sentry captures errors only.Why
Next.js splits
@sentry/coreacross server chunks, which made trace connection between OpenTelemetry telemetry and Sentry errors fail in exactly the setup the integration exists for.