open-telemetry / open-telemetry/opentelemetry-python-contrib
FastAPI instrumenter not respecting traceparent sampling
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
OS: Ubuntu & windows
Python version: 3.10
Package version: 1.6.7
What happened?
I am using Open Telemetry fast api intrumentor, where I want the logs to be correlated using w3c for incoming requests.
This works OK, so if I get a request that is forwarded from another service, the logs have the same operation ID when they are collected to azure.
But when the forwarded request has a traceparent header with the sample flag OFF (e.g 00-3e4cb418448aad7300ca890e7d1b3980-432829696627be4a-00), the fastapi instrumentation is still logging the backend operations to Azure.
Is this the expected outcome? I would like that it only logs requests that are marked not to be sampled in the traceparent, that it is also not logged in my fastapi app.
Steps to Reproduce
Send request to API with header traceparent with sample flag off (and env set OTEL_TRACES_SAMPLER="parentbased_always_off")
Expected Result
No logging in app/ sent to azure
Actual Result
Logs are sent for requests with header with sample flag both ON and OFF
Additional context
No response
Would you like to implement a fix?
None
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
Start with the FastAPI instrumentor and reproduce the request using a W3C traceparent header whose sample flag is off, together with OTEL_TRACES_SAMPLER="parentbased_always_off". Trace how sampling affects the request's emitted logs or telemetry, then verify that unsampled requests produce no app or Azure logs while sampled requests retain their current behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, backend, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100