feat(integrations): Add http.route attribute to server spans - #7183
Conversation
Codecov Results 📊✅ 121590 passed | ⏭️ 6762 skipped | Total: 128352 | Pass Rate: 94.73% | Execution Time: 429m 51s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 98.18%. Project has 2486 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 90.30% 90.34% +0.04%
==========================================
Files 193 193 —
Lines 25689 25734 +45
Branches 9480 9504 +24
==========================================
+ Hits 23198 23248 +50
- Misses 2491 2486 -5
- Partials 1442 1445 +3Generated by Codecov Action |
dddf367 to
b1363a5
Compare
…#7201) 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. Found while working on #7183.
…#7201) 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. Found while working on #7183.
b1363a5 to
1d15a6d
Compare
http.route attribute to HTTP server spans| for attribute, value in attributes.items(): | ||
| self.set_attribute(attribute, value) | ||
|
|
||
| def set_segment_attribute(self, key: str, value: "AttributeValue") -> None: |
There was a problem hiding this comment.
This seemed like a useful helper function to have (and avoids duplicating this code in every HTTP integration), but I would also understand if we don't want to expand the API surface with this: it makes the "segment" name a public thing which AIUI we are trying to avoid? I'm not sure the best path forward here.
### Description When host routing, we don't have a route and instead fall back to the request path for the transaction name. This should be given transaction source `url` (for raw URLs) instead of the current value of `route` (for parameterized routes). This matters for #7183, where the mis-categorized transaction source would lead to bad data in `http.route`. (Bug found by Cursor in #7183 (comment) when reviewing that PR).
fdd83b4 to
2b3c0c5
Compare
2b3c0c5 to
20d2496
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 20d2496. 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