Skip to content

fix(spans): Add http.route attribute to HTTP server spans - #7183

Draft
mjq wants to merge 1 commit into
masterfrom
mjq/http-route-server-spans
Draft

fix(spans): Add http.route attribute to HTTP server spans#7183
mjq wants to merge 1 commit into
masterfrom
mjq/http-route-server-spans

Conversation

@mjq

@mjq mjq commented Aug 12, 2026

Copy link
Copy Markdown
Member

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 description generation, which will be necessary to maintain consistent descriptions between transactions and span streaming.

Issues

@linear-code

linear-code Bot commented Aug 12, 2026

Copy link
Copy Markdown

PY-2732

@mjq

mjq commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@sentry review

@mjq

mjq commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread sentry_sdk/scope.py
"sentry.segment.name.source", source_value
)
if source_value == SegmentNameSource.ROUTE.value:
self._span._segment.set_attribute(SPANDATA.HTTP_ROUTE, name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dddf367. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

112468 passed | ⏭️ 6759 skipped | Total: 119227 | Pass Rate: 94.33% | Execution Time: 408m 0s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +5
Passed Tests 📈 +5
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 90.00%. Project has 2486 uncovered lines.
❌ Project coverage is 90.2%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/asgi.py 80.00% ⚠️ 1 Missing and 1 partials
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        -3

Generated by Codecov Action

)
if (
source == SegmentNameSource.ROUTE.value
and name != _DEFAULT_TRANSACTION_NAME

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py set_transaction_name unconditionally sets SPANDATA.HTTP_ROUTE whenever source_value == SegmentNameSource.ROUTE.value, without checking name != _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.route to 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http.route missing from HTTP server spans

1 participant