fix(starlette): Set transaction name on current scope in sync handler - #7201
Draft
mjq wants to merge 1 commit into
Draft
fix(starlette): Set transaction name on current scope in sync handler#7201mjq wants to merge 1 commit into
mjq wants to merge 1 commit into
Conversation
The sync request/response handler passed the _isolation_ scope to `_set_transaction_name_and_source`, but the transaction/segment span lives on the _current_ scope. As a result the route-resolved name never reached the span for sync endpoints, which were instead named by the raw URL from the ASGI middleware (`transaction_info.source` of `url` rather than `route`). Async handlers already used the current scope and were unaffected. Pass the current scope (already computed above) so sync and async handlers behave identically: - streaming: the segment name / `sentry.segment.name.source` are route-based - static: the transaction event name / source are route-based For parametrized routes this also removes high-cardinality URL transaction names for sync endpoints.
mjq
force-pushed
the
mjq/starlette-sync-scope-fix
branch
from
August 13, 2026 20:44
e043a2f to
b6107ba
Compare
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 b6107ba. Configure here.
Contributor
Codecov Results 📊✅ 113327 passed | ⏭️ 6769 skipped | Total: 120096 | Pass Rate: 94.36% | Execution Time: 418m 15s 📊 Comparison with Base Branch
➖ Removed Tests (1)View removed tests
All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 2490 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 90.21% 90.21% —%
==========================================
Files 193 193 —
Lines 25423 25423 —
Branches 9336 9336 —
==========================================
+ Hits 22933 22933 —
- Misses 2490 2490 —
- Partials 1436 1437 +1Generated by Codecov Action |
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.
The sync request/response handler passed the isolation scope to
_set_transaction_name_and_source, but the transaction/segment span lives on the current scope. As a result the route-resolved name never reached the span for sync endpoints, which were instead named by the raw URL from the ASGI middleware (transaction_info.sourceofurlrather thanroute). Async handlers already used the current scope and were unaffected.Pass the current scope (already computed above) so sync and async handlers behave identically:
sentry.segment.name.sourceare route-basedFor parametrized routes this also removes high-cardinality URL transaction names for sync endpoints.
Found while working on #7183.