René's URL Explorer Experiment


Title: Next.js middleware: `normalizedRequest` never reaches `tracesSampler` on the edge runtime, so #21833 has no effect there · Issue #22200 · getsentry/sentry-javascript · GitHub

Open Graph Title: Next.js middleware: `normalizedRequest` never reaches `tracesSampler` on the edge runtime, so #21833 has no effect there · Issue #22200 · getsentry/sentry-javascript

X Title: Next.js middleware: `normalizedRequest` never reaches `tracesSampler` on the edge runtime, so #21833 has no effect there · Issue #22200 · getsentry/sentry-javascript

Description: Summary #21833 wired the isolation scope's normalizedRequest into the tracesSampler sampling context for root spans, so a custom sampler can decide from the incoming request. Its stated motivation is exactly the use case below ("drop hea...

Open Graph Description: Summary #21833 wired the isolation scope's normalizedRequest into the tracesSampler sampling context for root spans, so a custom sampler can decide from the incoming request. Its stated motivation ...

X Description: Summary #21833 wired the isolation scope's normalizedRequest into the tracesSampler sampling context for root spans, so a custom sampler can decide from the incoming request. Its stated motivat...

Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/22200

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Next.js middleware: `normalizedRequest` never reaches `tracesSampler` on the edge runtime, so #21833 has no effect there","articleBody":"## Summary\n\n[#21833](https://github.com/getsentry/sentry-javascript/pull/21833) wired the isolation scope's `normalizedRequest` into the `tracesSampler` sampling context for root spans, so a custom sampler can decide from the incoming request. Its stated motivation is exactly the use case below (\"drop health-check routes\").\n\n**On the Next.js edge runtime (middleware) the value never arrives.** `tracesSampler` is called for every `middleware GET` root span with `normalizedRequest: undefined`, so the request cannot be inspected at all. The Node runtime, in the same app and with the same sampler, gets the full header bag.\n\nThe practical consequence is that **middleware traces cannot be sampled by anything about the request** (no URL, no route, no User-Agent), so a sampler cannot drop synthetic traffic there.\n\n## Versions\n\n| | |\n|---|---|\n| `@sentry/nextjs` | 10.63.0 |\n| `@sentry/core` | 10.63.0 |\n| `@sentry/vercel-edge` | 10.63.0 |\n| `next` | 16.2.10 |\n| Node | 22.22.0 |\n\nReproduced on a real `next build && next start`, and observed in production on Vercel.\n\n## Evidence\n\nI instrumented my `tracesSampler` to log what it is handed, then drove one request with a marked User-Agent and one without:\n\n```\n[SAMPLER-PROBE] {\"name\":\"GET /health\",    \"hasNormalizedRequest\":true,  \"headerKeys\":[\"host\",\"user-agent\",\"accept\"], \"ua\":\"Mozilla/5.0 ... my-e2e/1\", \"rate\":0}\n[SAMPLER-PROBE] {\"name\":\"middleware GET\", \"hasNormalizedRequest\":false, \"headerKeys\":[],                             \"rate\":1}\n[SAMPLER-PROBE] {\"name\":\"GET /health\",    \"hasNormalizedRequest\":true,  \"headerKeys\":[\"host\",\"user-agent\",\"accept\"], \"ua\":\"Mozilla/5.0 ...\",          \"rate\":1}\n[SAMPLER-PROBE] {\"name\":\"middleware GET\", \"hasNormalizedRequest\":false, \"headerKeys\":[],                             \"rate\":1}\n```\n\n`hasNormalizedRequest` is **`false` for every middleware span**, including the one whose request carried the marker. The header bag is empty. The Node span, one line above and in the same request, gets the full bag.\n\n`beforeSendTransaction` cannot recover it either: a `event.request.headers['user-agent']` check never fires on these events, which suggests the finished transaction has no request data either, not just the sampling context.\n\n## What I traced in the source (the chain looks correct, and the value still does not arrive)\n\n- `@sentry/nextjs/build/cjs/common/wrapMiddlewareWithSentry.js:33` calls `isolationScope.setSDKProcessingMetadata({ normalizedRequest: winterCGRequestToRequestData(req) })`, **before** `startSpan` on line 51.\n- `winterCGRequestToRequestData` (`@sentry/core` `utils/request.js`) returns `{ method, url, query_string, headers }` with the full header dict.\n- `@sentry/core` `tracing/trace.js` builds the sampling context with `normalizedRequest: getIsolationScope().getScopeData().sdkProcessingMetadata.normalizedRequest`.\n- `tracing/sampling.js` calls `options.tracesSampler(...)` first, with no short-circuit.\n- The sampler is definitely installed on edge (it is in `sentry.edge.config.ts`, and it runs: the probe above is its own output).\n\nSo every link exists, and the isolation scope the wrapper writes to does not appear to be the one the sampler reads from on this runtime. I have not chased which of the two it is.\n\n## Steps to reproduce\n\n1. Next.js app with `@sentry/nextjs` and a `middleware.ts` matching normal routes.\n2. In `sentry.edge.config.ts` **and** `sentry.server.config.ts`, install the same sampler:\n\n```ts\nSentry.init({\n  dsn: process.env.SENTRY_DSN,\n  tracesSampler: (ctx) => {\n    console.log(JSON.stringify({\n      name: ctx.name,\n      hasNormalizedRequest: Boolean(ctx.normalizedRequest),\n      headerKeys: Object.keys(ctx.normalizedRequest?.headers ?? {}),\n    }));\n    return 1;\n  },\n});\n```\n\n3. `next build && next start`, then `curl http://localhost:3000/any-page`.\n4. The `middleware GET` line reports `hasNormalizedRequest: false` with an empty `headerKeys`. The Node route's line reports `true` with the headers.\n\n## Expected\n\n`tracesSampler` receives `normalizedRequest` for middleware root spans on the edge runtime, as it does on Node, so #21833's \"decide from the incoming request\" works on every runtime.\n\n## Actual\n\n`normalizedRequest` is `undefined` for every edge (middleware) root span, so the sampler has only `ctx.name` to go on.\n\n## Workaround, for anyone who finds this\n\nThe only thing the sampler is given on edge is the span name, so I match on it and refuse the trace outright:\n\n```ts\nconst isMiddlewareSpan = (name?: string) =>\n  typeof name === 'string' && (name === 'middleware' || name.startsWith('middleware '));\n\ntracesSampler: (ctx) => (isMiddlewareSpan(ctx.name) ? 0 : /* your real policy */ 1),\n```\n\nThis costs the middleware traces of real users too, which is only acceptable because those spans land with no url, no route and no User-Agent anyway, so they cannot be attributed to a user or an endpoint. Errors are unaffected (`captureException` is governed by `sampleRate`, not `tracesSampler`).\n\nFor context on why this mattered enough to chase: these unsampleable middleware spans, plus the Supabase auth call each one makes as a child of the same trace, were ~90% of the spans our CI was still sending after we thought we had silenced it.","author":{"url":"https://github.com/gerokeller","@type":"Person","name":"gerokeller"},"datePublished":"2026-07-12T14:57:17Z","url":"https://github.com/getsentry/sentry-javascript/issues/22200"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:35f42a56-360f-2da7-0f34-0ada90a9bb16
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8BD8:2F6550:1B82F3B:247B6DD:6B0426E1
html-safe-noncee587c84b14457af8b0d41b22f31b0c0202c7daa21d68143a7908a371cfcd1d3f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkQ4OjJGNjU1MDoxQjgyRjNCOjI0N0I2REQ6NkIwNDI2RTEiLCJ2aXNpdG9yX2lkIjoiNDIxNzgxMzc5Mzc4MDI3OTAwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfb9b25bacceb28966cdec1e609c41d47f52468fa03161931f93909ce15810aa8
hovercard-subject-tagissue:4867508465
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/22200/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d448bba0ca4375f060baf0f4ee556166180ad826461e20f27569b2a4eb55c8b2/getsentry/sentry-javascript/issues/22200
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d448bba0ca4375f060baf0f4ee556166180ad826461e20f27569b2a4eb55c8b2/getsentry/sentry-javascript/issues/22200
og:image:altSummary #21833 wired the isolation scope's normalizedRequest into the tracesSampler sampling context for root spans, so a custom sampler can decide from the incoming request. Its stated motivation ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegerokeller
hostnamegithub.com
expected-hostnamegithub.com
Noneb7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3328572
octolytics-dimension-repository_nwogetsentry/sentry-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3328572
octolytics-dimension-repository_network_root_nwogetsentry/sentry-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec3dd496c3da6ea6b77e69c09279d2b81604654f1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-javascript/issues/22200#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F22200
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F22200
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-javascript
Reloadhttps://github.com/getsentry/sentry-javascript/issues/22200
Reloadhttps://github.com/getsentry/sentry-javascript/issues/22200
Reloadhttps://github.com/getsentry/sentry-javascript/issues/22200
getsentryhttps://github.com/getsentry
sentry-javascripthttps://github.com/getsentry/sentry-javascript
Codehttps://github.com/getsentry/sentry-javascript
Issues339 (339)https://github.com/getsentry/sentry-javascript/issues
Pull requests59 (59)https://github.com/getsentry/sentry-javascript/pulls
Discussionshttps://github.com/getsentry/sentry-javascript/discussions
Actionshttps://github.com/getsentry/sentry-javascript/actions
Security and quality7 (7)https://github.com/getsentry/sentry-javascript/security
Insightshttps://github.com/getsentry/sentry-javascript/insights
https://github.com/getsentry/sentry-javascript
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/22200
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/22200
#22232https://github.com/getsentry/sentry-javascript/pull/22232
Next.js middleware: normalizedRequest never reaches tracesSampler on the edge runtime, so #21833 has no effect therehttps://github.com/getsentry/sentry-javascript/issues/22200#top
#22232https://github.com/getsentry/sentry-javascript/pull/22232
https://github.com/s1gr1d
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Next.jshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Next.js%22
https://github.com/gerokeller
gerokellerhttps://github.com/gerokeller
on Jul 12, 2026https://github.com/getsentry/sentry-javascript/issues/22200#issue-4867508465
#21833https://github.com/getsentry/sentry-javascript/pull/21833
#21833https://github.com/getsentry/sentry-javascript/pull/21833
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jul 12, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-27875474800
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jul 12, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-27875476339
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jul 12, 2026https://github.com/getsentry/sentry-javascript/issues/22200
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Jul 12, 2026https://github.com/getsentry/sentry-javascript/issues/22200#issuecomment-4951625166
Linear Codehttps://linear.app
JS-3007https://linear.app/getsentry/issue/JS-3007
linear-codehttps://github.com/apps/linear-code
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Next.jshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Next.js%22
on Jul 12, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-27875486878
s1gr1dhttps://github.com/s1gr1d
on Jul 13, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-27905928790
https://github.com/s1gr1d
s1gr1dhttps://github.com/s1gr1d
on Jul 13, 2026https://github.com/getsentry/sentry-javascript/issues/22200#issuecomment-4959407412
fix(nextjs): Handle Middleware.execute root spans on Node.js runtime #22013https://github.com/getsentry/sentry-javascript/pull/22013
Fix instrumentation hook awaiting for middleware with adapters vercel/next.js#95357https://github.com/vercel/next.js/pull/95357
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jul 13, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-27915400851
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jul 13, 2026https://github.com/getsentry/sentry-javascript/issues/22200
chargomehttps://github.com/chargome
completedhttps://github.com/getsentry/sentry-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#22232https://github.com/getsentry/sentry-javascript/pull/22232
on Jul 22, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-28313603452
chargomehttps://github.com/chargome
on Jul 22, 2026https://github.com/getsentry/sentry-javascript/issues/22200#event-28313603542
fix(nextjs): Make request data available to `tracesSampler` for edge …https://github.com/getsentry/sentry-javascript/commit/56c8ca37100edbb5010dc9e8018b5b19211cc92a
56c8ca3https://github.com/getsentry/sentry-javascript/commit/56c8ca37100edbb5010dc9e8018b5b19211cc92a
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Sep 23, 2026https://github.com/getsentry/sentry-javascript/issues/22200#issuecomment-5795101381
GitHub Actionshttps://help.github.com/en/actions
#22232https://github.com/getsentry/sentry-javascript/pull/22232
11.0.0 releasehttps://github.com/getsentry/sentry-javascript/releases/tag/11.0.0
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-javascript/issues/22200
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/22200
s1gr1dhttps://github.com/s1gr1d
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Next.jshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Next.js%22
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.