Fix OpenTelemetry API singleton in server bundles#95743
Closed
bryan-hunter wants to merge 2 commits into
Closed
Conversation
Contributor
Stats from current PR🟢 1 improvement
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: 52448b5 |
Contributor
Tests PassedCommit: 52448b5 |
Author
|
this seems to solve it, so will close! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@opentelemetry/apifrom server bundles so route code and instrumentation use the same process-wide singleton.serverExternalPackageslist.Problem
A production route can acquire its tracer when the route module is evaluated:
Instrumentation registers the provider later:
This ordering is supported by OpenTelemetry's proxy API. It broke when the route bundle contained API copy A while instrumentation loaded API copy B: registering the provider on B never activated the tracer from A, so custom spans stayed no-op.
Externalizing
@opentelemetry/apimakes both imports resolve to the same singleton, allowing an early tracer to delegate to the provider after registration.Reproduction
The E2E fixture reproduces the production sequence: preload the generated route, acquire its module-scope tracer, register OpenTelemetry, then invoke the route.
pnpm test-start-turbo test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts \ -t "records spans from a tracer acquired before instrumentation registration"module-scope-tracer.Observed versions
16.1.616.2.10These sampled counts establish presence versus absence, not exact traffic volume. The application upgrade also changed its instrumentation integration, so the production comparison identifies the observed boundary but does not isolate Next.js by itself; the E2E negative control above isolates the server bundling behavior.
Target: canary, with a backport to the maintained
16.2.xline.Testing
pnpm --filter=next typespnpm validate-externals-doc