opentelemetry-instrumentation-tornado: reduce cardinality of span names and metrics attributes#4577
Merged
Conversation
Reduce metrics cardinality for new stable path by dropping the usage or URL_PATH and URL_QUERY in favor of HTTP_ROUTE.
5399441 to
77c70b1
Compare
lzchen
reviewed
May 13, 2026
lzchen
reviewed
May 13, 2026
There was a problem hiding this comment.
Pull request overview
This PR reduces Tornado instrumentation cardinality by deriving route-based span names and stable HTTP metric attributes instead of using concrete request paths/query components.
Changes:
- Adds route discovery utilities for Tornado handlers.
- Updates server span naming and stable metric attributes to use
http.route. - Adds test app routes and assertions for parameterized URL behavior and metric attributes.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/_utils.py |
Adds route matching and route formatting helpers. |
instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py |
Uses matched routes for span names and stable server metric attributes. |
instrumentation/opentelemetry-instrumentation-tornado/tests/tornado_test_app.py |
Adds a parameterized test handler and route. |
instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py |
Adds span-name coverage for parameterized routes. |
instrumentation/opentelemetry-instrumentation-tornado/tests/test_metrics_instrumentation.py |
Adds stable metric attribute assertions for route/query/path handling. |
.changelog/4577.fixed |
Documents the cardinality fix and stable metric attribute change. |
aabmass
approved these changes
May 13, 2026
8cfb70d to
7bc1cab
Compare
lzchen
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes two cardinality issues for the tornado instrumentation:
url.query,url.pathin favor of in-spechttp.route. For older semantic conventions this is not possible sincehttp.targetis high cardinality by definition.Since Tornado does not offer us any helper to get the templated name of a route from the handler we need to introduce a basic reimplementation of its routing algorithm. We then reuse a tornado internal method to subsitute the regexp groups in the rule with some names taken from the handler method function parameters, this internal function has been there since ages so I think it's pretty safe to reuse.
Assisted-by: Cursor
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.