Skip to content

opentelemetry-instrumentation-tornado: reduce cardinality of span names and metrics attributes#4577

Merged
xrmx merged 7 commits into
open-telemetry:mainfrom
xrmx:tornado-stop-using-request-path
May 15, 2026
Merged

opentelemetry-instrumentation-tornado: reduce cardinality of span names and metrics attributes#4577
xrmx merged 7 commits into
open-telemetry:mainfrom
xrmx:tornado-stop-using-request-path

Conversation

@xrmx
Copy link
Copy Markdown
Contributor

@xrmx xrmx commented May 13, 2026

Description

This PR fixes two cardinality issues for the tornado instrumentation:

  • in the span name, where we are now using a low-cardinality version of the request path
  • in the metrics attributes for stable http semantic conventions. This changes the attributes of some of the metrics dropping out of spec url.query, url.path in favor of in-spec http.route. For older semantic conventions this is not possible since http.target is 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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • tox

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

xrmx added 2 commits May 13, 2026 15:40
Reduce metrics cardinality for new stable path by dropping the usage or
URL_PATH and URL_QUERY in favor of HTTP_ROUTE.
@xrmx xrmx force-pushed the tornado-stop-using-request-path branch from 5399441 to 77c70b1 Compare May 13, 2026 13:43
@xrmx xrmx requested a review from a team as a code owner May 13, 2026 13:43
@xrmx xrmx moved this to Ready for review in Python PR digest May 13, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@xrmx xrmx force-pushed the tornado-stop-using-request-path branch from 8cfb70d to 7bc1cab Compare May 15, 2026 15:41
@github-project-automation github-project-automation Bot moved this from Ready for review to Approved PRs in Python PR digest May 15, 2026
@xrmx xrmx enabled auto-merge (squash) May 15, 2026 16:10
@xrmx xrmx merged commit a5fa648 into open-telemetry:main May 15, 2026
753 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants