Skip to content

fix(react-router): Key server middleware counter by root span, not OTel context - #22982

Merged
andreiborza merged 2 commits into
developfrom
ab/fix-rr-middleware-counter
Aug 4, 2026
Merged

fix(react-router): Key server middleware counter by root span, not OTel context#22982
andreiborza merged 2 commits into
developfrom
ab/fix-rr-middleware-counter

Conversation

@andreiborza

Copy link
Copy Markdown
Member

What

Store the server instrumentation-API middleware index counter in a WeakMap keyed by the request's root span, instead of on the OpenTelemetry context.

Why

The counter lived on the OTel context, which does not propagate when no tracer provider is set up. In that case it reset to 0 for every middleware, so all middleware spans on a route reported react_router.middleware.index: 0 instead of 0, 1, 2, .... The root span is the single transaction all of a request's middlewares run under, so keying on it increments correctly regardless of whether a provider is active.

…el context

The server instrumentation-API middleware index counter was stored on the
OpenTelemetry context. Without a tracer provider the context does not propagate, so
the counter reset to 0 on every middleware and all middleware spans reported index 0.
Key the counter by the request's root span (the single transaction all of a request's
middlewares run under) in a WeakMap instead, so the index increments in every mode.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.81 kB - -
@sentry/browser - with treeshaking flags 28.03 kB - -
@sentry/browser (incl. Tracing) 47.28 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.29 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.05 kB - -
@sentry/browser (incl. Tracing, Replay) 86.6 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.04 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 91.33 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.97 kB - -
@sentry/browser (incl. Feedback) 47.13 kB - -
@sentry/browser (incl. sendFeedback) 34.66 kB - -
@sentry/browser (incl. FeedbackAsync) 39.77 kB - -
@sentry/browser (incl. Metrics) 30.88 kB - -
@sentry/browser (incl. Logs) 31.12 kB - -
@sentry/browser (incl. Metrics & Logs) 31.79 kB - -
@sentry/react 31.61 kB - -
@sentry/react (incl. Tracing) 49.54 kB - -
@sentry/vue 34.88 kB - -
@sentry/vue (incl. Tracing) 49.27 kB - -
@sentry/svelte 29.83 kB - -
CDN Bundle 31.9 kB - -
CDN Bundle (incl. Tracing) 47.6 kB - -
CDN Bundle (incl. Logs, Metrics) 33.45 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.02 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 72.81 kB - -
CDN Bundle (incl. Tracing, Replay) 85.26 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.57 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.08 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.4 kB - -
CDN Bundle - uncompressed 94.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.47 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.51 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.44 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.26 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.72 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.69 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.43 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.38 kB - -
@sentry/nextjs (client) 52.1 kB - -
@sentry/sveltekit (client) 47.72 kB - -
@sentry/core/server 65.53 kB +0.02% +8 B 🔺
@sentry/core/browser 51.87 kB +0.02% +10 B 🔺
@sentry/node 120.65 kB +0.01% +1 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 84.03 kB -0.01% -1 B 🔽
@sentry/aws-serverless 92.69 kB -0.01% -2 B 🔽
@sentry/cloudflare (withSentry) - minified 218.64 kB +0.01% +20 B 🔺
@sentry/cloudflare (withSentry) 538.65 kB +0.02% +74 B 🔺

View base workflow run

@andreiborza

andreiborza commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

buglitzer moch

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f06ad0d. Configure here.

@andreiborza
andreiborza marked this pull request as ready for review August 4, 2026 13:21
@andreiborza
andreiborza requested a review from a team as a code owner August 4, 2026 13:21
@andreiborza
andreiborza requested review from chargome, nicohrubec and s1gr1d and removed request for a team and s1gr1d August 4, 2026 13:21
@andreiborza
andreiborza merged commit 3191118 into develop Aug 4, 2026
49 checks passed
@andreiborza
andreiborza deleted the ab/fix-rr-middleware-counter branch August 4, 2026 13:39
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.

2 participants