fix(v10/nextjs): Remove tracing from middleware wrappers - #22904
Merged
Conversation
Contributor
size-limit report 📦
|
Next.js only emits the native `Middleware.execute` OTel span from v14 onwards, so relying on it unconditionally dropped middleware transactions entirely on Next.js 13, which v10 still supports. Fall back to starting the wrapper span when no root span is active.
chargome
marked this pull request as ready for review
July 31, 2026 14:15
chargome
requested review from
a team,
logaretm,
nicohrubec and
s1gr1d
and removed request for
a team
July 31, 2026 14:15
Member
Author
|
@logaretm this just conditionally adds the tracing for v13 |
logaretm
approved these changes
Jul 31, 2026
andreiborza
approved these changes
Jul 31, 2026
Merged
6 tasks
sergical
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Jul 31, 2026
…#18887) ## DESCRIBE YOUR PR #18775 dropped middleware root spans entirely; this restores them at a blind 1% (~24k/day), blind because Next.js creates the `Middleware.execute` root in a detached sandbox before any request data reaches Sentry, so `tracesSampler` can never classify it. `middleware.ts` tags that span with `middleware.outcome` (redirect/rewrite/passthrough), `url.path`, `traffic_type`, and `device_type` — attributes rather than a span name, because the SDK's `enhanceMiddlewareRootSpan` unconditionally rewrites `Middleware.execute` names to `middleware {METHOD}` on the send path and ignores `sentry.source`. `isMiddlewareRootSpan` now matches both `http.server.middleware` (SDK v10) and `middleware` (v11) so detection survives the upgrade. Note that v10 still emits a duplicate nested middleware span, so volume may be ~2x until getsentry/sentry-javascript#22904 lands — unrelated to this rate, and a non-zero rate is what makes that fix observable here at all. To verify after deploy: `spans · span.op:http.server.middleware · release:<new sha>` is non-zero at ~1% of request volume with `middleware.outcome` populated, and `docs.request.classified` grouped by `traffic_type` is unchanged. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Backport of: #18456
Fixes #22636