Skip to content

fix(nextjs): Drop the request span that only runs the proxy - #25386

Draft
Lms24 wants to merge 2 commits into
developfrom
lms/fix-nextjs-proxy-handle-request-segment
Draft

Lms24 wants to merge 2 commits into
developfrom
lms/fix-nextjs-proxy-handle-request-segment

Conversation

@Lms24

@Lms24 Lms24 commented Oct 15, 2026

Copy link
Copy Markdown
Member

Behind a proxy, Next.js runs each request through two handleRequest calls: one only runs the proxy, the other renders the route. Since Next.js 16.3 the proxy span is no longer a child of the first call's span, so that span became an empty GET segment with op http.server, counted next to the real one. We now drop it at span start, using the middlewareInvoke flag Next.js sets on the request. At start, its attributes are the same as the real span's.

For this, core keeps the incoming request on the request's isolation scope, and enforces the beforeSampling decision again. It stopped doing that when SentrySampler was removed, which also silently disabled the existing Next.js drop of Sentry ingest requests.

Fixes #25370

🤖 Generated with Claude Code

Lms24 and others added 2 commits October 14, 2026 19:18
…roxy

Requests behind the proxy produce an extra route-less `GET` segment with
op `http.server` next to the route segment. This test shows it for an API
route and a page.

Refs #25370
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Since Next.js 16.3 the proxy span is no longer a child of the
`BaseServer.handleRequest` span that runs it, so that span became an empty
`http.server` segment next to the one of the route. Drop it at span start
in `beforeSampling`, based on the `middlewareInvoke` flag Next.js sets on
the request. Its attributes at start are the same as the route's.

For this, core now keeps the incoming request on the request's isolation
scope and enforces the `beforeSampling` decision again, which it had
stopped doing when `SentrySampler` was removed.

Fixes #25370
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bcb8427. Configure here.

expect(segmentSpans.map(span => span.name).sort()).toEqual([`GET ${path}`, 'middleware GET']);
expect(segmentSpans.filter(span => getSpanOp(span) === 'http.server').map(span => span.name)).toEqual([
`GET ${path}`,
]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Span op asserted as string literal

Low Severity

The new segment assertion compares getSpanOp to the string 'http.server'. Testing conventions require span-op assertions to use the @sentry/conventions constant rather than a literal. Flagged because it is called out in the PR review rules.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit bcb8427. Configure here.

`GET ${path}`,
]);
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loop registers scenarios instead of test.each

Low Severity

A for loop registers the same proxy-segment test for two paths. Testing conventions call for test.each when one case covers multiple scenarios, instead of generating tests in a loop. Flagged because it is called out in the PR review rules.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit bcb8427. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.88 kB - -
@sentry/browser - with treeshaking flags 28.02 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.92 kB - -
@sentry/browser (incl. Tracing) 52.08 kB +0.02% +7 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.08 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.03 kB +0.02% +11 B 🔺
@sentry/browser (incl. Tracing, Replay) 91.83 kB +0.02% +12 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.7 kB +0.03% +18 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 96.56 kB +0.02% +13 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 109.5 kB +0.02% +12 B 🔺
@sentry/browser (incl. Feedback) 47.4 kB - -
@sentry/browser (incl. sendFeedback) 34.94 kB - -
@sentry/browser (incl. FeedbackAsync) 40.05 kB - -
@sentry/browser (incl. Metrics) 30.9 kB - -
@sentry/browser (incl. Logs) 31.18 kB - -
@sentry/browser (incl. Metrics & Logs) 31.81 kB - -
@sentry/react 31.7 kB - -
@sentry/react (incl. Tracing) 54.4 kB +0.03% +11 B 🔺
@sentry/vue 38.05 kB +0.04% +14 B 🔺
@sentry/vue (incl. Tracing) 55.02 kB +0.02% +10 B 🔺
@sentry/svelte 29.9 kB - -
@sentry/remix (Remix 3 client bundle) 57.1 kB +0.03% +17 B 🔺
CDN Bundle 31.64 kB - -
CDN Bundle (incl. Tracing) 52.6 kB +0.03% +14 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.84 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.54 kB +0.03% +15 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.77 kB - -
CDN Bundle (incl. Tracing, Replay) 90.26 kB +0.02% +11 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.19 kB +0.02% +13 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 96.41 kB +0.02% +10 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.36 kB +0.02% +12 B 🔺
CDN Bundle - uncompressed 93.18 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.06 kB +0.02% +25 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.02 kB +0.02% +25 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.76 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.23 kB +0.01% +25 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.17 kB +0.01% +25 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.93 kB +0.01% +25 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.86 kB +0.01% +25 B 🔺
@sentry/nextjs (client) 56.81 kB +0.03% +16 B 🔺
@sentry/sveltekit (client) 52.46 kB +0.03% +14 B 🔺
@sentry/core/server 41.16 kB +0.09% +36 B 🔺
@sentry/core/browser 13.83 kB +0.13% +17 B 🔺
@sentry/node 152.52 kB +0.04% +55 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.81 kB - -
@sentry/node - without tracing 94.65 kB +0.05% +41 B 🔺
@sentry/node - without channel injection 130.74 kB +0.04% +50 B 🔺
@sentry/aws-serverless 102.81 kB +0.05% +45 B 🔺
@sentry/cloudflare (withSentry) - minified 210.62 kB +0.02% +25 B 🔺
@sentry/cloudflare (withSentry) 522.69 kB +0.04% +164 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 229.15 kB +0.39% +878 B 🔺

View base workflow run

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nextjs: Next 16 request yields a route-less http.server segment named only by method, plus the route-named one

1 participant