Skip to content

opentelemetry-instrumentation-starlette: omit unavailable http.route - #5276

Open
herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:fix/starlette-host-route
Open

herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:fix/starlette-host-route

Conversation

@herin049

@herin049 herin049 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Omit http.route when the matched Starlette route has no path template instead of using the raw request path. Host-routed spans fall back to the HTTP method as their name.

Per HTTP semantic conventions:

The matched route template for the request. This MUST be low-cardinality and include all static path segments, with dynamic path segments represented with placeholders. [5] http.route: MUST NOT be populated when this is not supported by the HTTP server framework as the route attribute should have low-cardinality and the URI path can NOT substitute it.

Fixes #5275

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Validation: 67 tests passed with Starlette 0.13.8 and 67 with 0.46.2; Ruff lint/format and Pylint passed.

Checklist:

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-01 16:55 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@herin049
herin049 marked this pull request as ready for review November 1, 2026 16:51
@herin049
herin049 requested a review from a team as a code owner November 1, 2026 16:51
@herin049
herin049 requested a balanced review from Copilot November 1, 2026 16:51

Copilot AI left a comment

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.

🟡 Changes recommended

Host-routed WebSocket connections lose their server span name because their scopes lack a method, requiring a scope-type fallback and a regression test.

1 open issue
What changed in this PR

This PR addresses #5275 by preventing Starlette instrumentation from using raw request paths as http.route when a matched route has no path template.

Changes:

  • Omit unavailable route attributes and use the HTTP method as the fallback span name.
  • Add a regression test for host-routed HTTP requests.
  • Document the fix in the changelog.
File Description
instrumentation/​opentelemetry-instrumentation-starlette/​tests/​test_starlette_instrumentation.py Verify host routing omits http.route and uses GET as the span name.
instrumentation/​opentelemetry-instrumentation-starlette/​src/​opentelemetry/​instrumentation/​starlette/​__init__.py Remove the raw request path fallback for routes without a template.
.changelog/​5276.fixed Record the route-attribute fix.

Review effort: Balanced

except AttributeError:
# routes added via host routing won't have a path attribute
route = scope.get("path")
route = None

This branch has not been deployed

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Starlette: host routing sets http.route to the raw request path

2 participants