open-telemetry / open-telemetry/opentelemetry-python-contrib

Route included in metrics auto-instrumentation ASGI

Open Beginner friendly
#1,316 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

There is a way to get the http.route included in autoinstrumented metrics for FastAPI?

Looking the following docs: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#parameterized-attributes

But the implementation of the recommended attributes doesn't include the http.route attribute:

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/18e056b85ae469fe6429cd45cbc1bc0db4cbc282/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py#L30-L48

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/18e056b85ae469fe6429cd45cbc1bc0db4cbc282/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py#L152-L165

Also the implementation of ASGI instrumentation, parse attributes for both metrics (duration and active_requests) after the addition of additional attributes (where the http.routes comes):
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/3c24adf1b2c95bf8fdca7de146e38922ef9581fe/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L446-L450

Is your feature request related to a problem?
Maybe the inclusion of path or route attributes, could be usefull for metrics analysis.

Describe the solution you'd like
Move the additional attributes update in the ASGI instrumentation, after the call of recommended attributes for metrics.

Describe alternatives you've considered
Manually instrumentation of all paths in the API.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/init.py around the metrics attribute handling, then review util/opentelemetry-util-http/src/opentelemetry/util/http/init.py and the linked HTTP metrics conventions. Confirm how additional attributes are added relative to recommended attributes, and verify that ASGI duration and active-request metrics include the route attribute without breaking existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
observability
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.