open-telemetry / open-telemetry/opentelemetry-python-contrib
Warning triggered by asgi.OpenTelemetryMiddleware
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
Describe your environment
Python: 3.10.7
opentelemetry-instrumentation-asgi: 0.33b0
opentelemetry-api 1.12.0
Fastapi: 0.79.0
Steps to reproduce
Setup the asgi middleware with fastapi as following:
app = fastapi.FastAPI()
app.add_middleware(OpenTelemetryMiddleware)
# Configure OTEL exporter
What is the expected behavior?
We should not see any warnings.
What is the actual behavior?
The following warning is raised multiple times.
An instrument with name http.server.duration, type Histogram, unit ms and description measures the duration of the inbound HTTP request has been created already.
Additional context
Seems to be related to https://github.com/open-telemetry/opentelemetry-python/issues/2558. This is the code triggering the issue
I imagine that somehow FastAPI is creating multiple instances of the middleware, and hence the instruments are created multiple times.
Labels: asgi, warning, fastapi
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the FastAPI setup with OpenTelemetryMiddleware and read opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/init.py around lines 195-202, alongside issue 2558. Trace why the http.server.duration instrument is created repeatedly and identify the relevant instrumentation path. Done means the reproduction no longer emits duplicate-instrument warnings, with regression coverage if the repository provides a suitable test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100