fix(spans): Add http.route attribute to HTTP server spans - #7183
Conversation
|
@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.
Reviewed by Cursor Bugbot for commit dddf367. Configure here.
| "sentry.segment.name.source", source_value | ||
| ) | ||
| if source_value == SegmentNameSource.ROUTE.value: | ||
| self._span._segment.set_attribute(SPANDATA.HTTP_ROUTE, name) |
There was a problem hiding this comment.
Generic names stored as http.route
Medium Severity
set_transaction_name writes http.route whenever the source is route, including generic fallback names such as generic Starlette request and generic FastAPI request. The ASGI path already skips those defaults, so unmatched or unresolved routes can still get a non-template http.route and skew HTTP server span descriptions.
Reviewed by Cursor Bugbot for commit dddf367. Configure here.
Codecov Results 📊✅ 112468 passed | ⏭️ 6759 skipped | Total: 119227 | Pass Rate: 94.33% | Execution Time: 408m 0s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 90.00%. Project has 2486 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 90.22% 90.20% -0.02%
==========================================
Files 193 193 —
Lines 25361 25371 +10
Branches 9302 9308 +6
==========================================
+ Hits 22880 22885 +5
- Misses 2481 2486 +5
- Partials 1436 1433 -3Generated 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


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