fix(react-router): Key server middleware counter by root span, not OTel context - #22982
Merged
Conversation
…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>
Contributor
size-limit report 📦
|
Member
Author
|
buglitzer moch |
There was a problem hiding this comment.
✅ 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
marked this pull request as ready for review
August 4, 2026 13:21
andreiborza
requested review from
chargome,
nicohrubec and
s1gr1d
and removed request for
a team and
s1gr1d
August 4, 2026 13:21
chargome
approved these changes
Aug 4, 2026
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.
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: 0instead 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.