fix(platform): Restore middleware spans at 1% with request attributes - #18887
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3 tasks
Contributor
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 42e0e02. Configure here.
chargome
approved these changes
Jul 31, 2026
chargome
left a comment
Member
There was a problem hiding this comment.
LGTM
re: Duplicate middleware spans, we fixed this on the upcoming v11 version but I"ll try to backport the fix to v10 today
Middleware roots now sample at a fixed 1% (~24k spans/day at current traffic) instead of 0. Because the rate is applied blind, bots are included in proportion to their share of traffic; middleware.ts stamps traffic_type onto the span so they stay filterable at query time. middleware.ts also names the span, which is what made these spans worth keeping. Next.js collapses the name to 'middleware GET'; setting sentry.source to 'custom' from inside the middleware stops the SDK reclaiming it. Spans are named by outcome (redirect / rewrite / passthrough) rather than by path — the docs site has thousands of paths plus every file under /mdx-images/, so naming by URL would blow up transaction-name cardinality. The path is kept as the url.path attribute. Note that send-time filtering is not an option here: beforeSendSpan is typed (span: SpanJSON) => SpanJSON with no null return, and with traceLifecycle 'stream' it is the only span hook, so spans cannot be dropped after creation. The blind sample rate is the only lever. docs.request.classified remains the unsampled system of record for traffic counting and is untouched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
No behavior change. Every span implementation reachable here returns `this` from updateName (SentrySpan, SentryNonRecordingSpan, OTel sdk-trace-base Span, OTel API NonRecordingSpan), so the chained form was safe, but core's own updateSpanName helper uses separate statements and this doesn't depend on a fluent return we don't control. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
sergical
force-pushed
the
sd/middleware-span-sampling
branch
from
July 31, 2026 12:41
42e0e02 to
3b6db28
Compare
…naming it
The outcome-based span name never survived. The SDK's enhanceMiddlewareRootSpan rewrites the name of every Middleware.execute span to `middleware {METHOD}` on the send path, reading Next.js' next.span_name attribute and ignoring sentry.source, so the rename here was silently discarded. Drop it and keep the redirect/rewrite/passthrough breakdown as the middleware.outcome attribute, which is queryable and keeps name cardinality flat.
Also match both middleware span ops in the sampler: http.server.middleware in v10, middleware in v11. next.span_type stays the load-bearing check either way.
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.

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.executeroot in a detached sandbox before any request data reaches Sentry, sotracesSamplercan never classify it.middleware.tstags that span withmiddleware.outcome(redirect/rewrite/passthrough),url.path,traffic_type, anddevice_type— attributes rather than a span name, because the SDK'senhanceMiddlewareRootSpanunconditionally rewritesMiddleware.executenames tomiddleware {METHOD}on the send path and ignoressentry.source.isMiddlewareRootSpannow matches bothhttp.server.middleware(SDK v10) andmiddleware(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 withmiddleware.outcomepopulated, anddocs.request.classifiedgrouped bytraffic_typeis unchanged.IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs to go live.
SLA
Thanks in advance for your help!
PRE-MERGE CHECKLIST
Make sure you've checked the following before merging your changes:
🤖 Generated with Claude Code