fix(spans): Add http.route attribute to HTTP server spans - #7183
Conversation
Codecov Results 📊✅ 112120 passed | ❌ 3 failed | ⏭️ 6763 skipped | Total: 118886 | Pass Rate: 94.31% | Execution Time: 404m 17s 📊 Comparison with Base Branch
➕ New Tests (3)View new tests
➖ Removed Tests (1)View removed tests
❌ Failed Tests
|
| File | Patch % | Lines |
|---|---|---|
| sentry_sdk/integrations/asgi.py | 80.00% |
Coverage diff
@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 90.21% 90.21% —%
==========================================
Files 193 193 —
Lines 25423 25444 +21
Branches 9336 9350 +14
==========================================
+ Hits 22933 22953 +20
- Misses 2490 2491 +1
- Partials 1436 1438 +2Generated by Codecov Action
| ) | ||
| if ( | ||
| source == SegmentNameSource.ROUTE.value | ||
| and name != _DEFAULT_TRANSACTION_NAME |
There was a problem hiding this comment.
scope.py sets http.route on default transaction names without matching guard
The ASGI middleware correctly avoids writing http.route for fallback transaction names, but scope.set_transaction_name() in the same PR lacks the same guard. When FastAPI or Starlette hit a 404 and call scope.set_transaction_name(default, ROUTE), http.route is set to a generic string rather than a route template.
Evidence
scope.pyset_transaction_nameunconditionally setsSPANDATA.HTTP_ROUTEwheneversource_value == SegmentNameSource.ROUTE.value, without checkingname != _DEFAULT_TRANSACTION_NAME.- Both FastAPI and Starlette call
scope.set_transaction_name(_DEFAULT_TRANSACTION_NAME, TransactionSource.ROUTE)when no route matches the request. - For streaming spans, that causes
http.routeto be set to values like "generic FastAPI request" in attributes, while this hunk explicitly avoids writing the attribute in the same circumstance.
Identified by Warden · code-review · DS5-DYC
dddf367 to
b1363a5
Compare
|
@sentry review |
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 b1363a5. Configure here.
| name = _DEFAULT_TRANSACTION_NAME | ||
| source = TransactionSource.ROUTE | ||
| elif source == TransactionSource.ROUTE: | ||
| scope.set_segment_attribute(SPANDATA.HTTP_ROUTE, name) |
There was a problem hiding this comment.
Starlette sync skips http.route
Medium Severity
set_segment_attribute only writes http.route when the given scope already holds a StreamedSpan. Starlette's sync handler calls _set_transaction_name_and_source with the isolation scope, whose _span is unset, so the attribute is silently dropped for sync endpoints. Async handlers use the current scope and are unaffected.
Reviewed by Cursor Bugbot for commit b1363a5. Configure here.


Description
Currently the HTTP path template is only available in the span name. Make it available as a semantic attribute as well (
http.route- definition in conventions).This will also let us use this in e.g. HTTP server span
descriptiongeneration, which will be necessary to maintain consistent descriptions between transactions and span streaming.Issues
http.routemissing from HTTP server spans #7182