fix(nextjs): Make request data available to tracesSampler for edge middleware root spans#22232
Open
s1gr1d wants to merge 4 commits into
Open
fix(nextjs): Make request data available to tracesSampler for edge middleware root spans#22232s1gr1d wants to merge 4 commits into
tracesSampler for edge middleware root spans#22232s1gr1d wants to merge 4 commits into
Conversation
s1gr1d
requested review from
chargome,
mydea and
nicohrubec
and removed request for
a team
July 13, 2026 15:42
chargome
reviewed
Jul 15, 2026
chargome
left a comment
Member
There was a problem hiding this comment.
Can we add one (unskipped) test case to verify the intent of this pr works correctly e2e in a non-cf scenario?
Contributor
|
👋 @mydea, @nicohrubec — Please review this PR when you get a chance! |
chargome
force-pushed
the
sig/nextjs-edge-middleware
branch
from
July 21, 2026 08:45
37ad847 to
4c49615
Compare
Contributor
|
👋 @mydea, @nicohrubec — Please review this PR when you get a chance! |
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.
On the edge runtime, Next.js's OTel instrumentation creates and samples the
Middleware.executeroot span before the Sentry middleware wrapper runs. SonormalizedRequestwas never on the isolation scope at sampling time, and tracesSampler received undefined.This adds a
beforeSamplinghook in the edge SDK which populatesnormalizedRequest(method, URL, query string) based on HTTP span attributes. It also extends the edgespanStarthandler to fork the isolation scope forMiddleware.executeroot spans (similar to what #22013 did on the Node side after vercel/next.js#95357 made middleware a detached root span).The isolation-scope fork is extracted into a shared
maybeForkIsolationScopeForRootSpanutility used by both the Node and edge handlers.Fixes #22200