open-telemetry / open-telemetry/opentelemetry-python-contrib
Traceparent header can disable trace recording when TraceContextTextMapPropagator is used
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
We are using the following libraries:
opentelemetry-sdk>=1.24.0,<1.25opentelemetry-exporter-otlp>=1.24.0,<1.25opentelemetry-instrumentation-flask==0.45b0
Steps to reproduce
Instrument a flask instance using something simple like:
FlaskInstrumentor(enable_commenter=True).instrument_app(
app, excluded_urls="/healthcheck")
Then, for any flask endpoint (that is not excluded), send an HTTP request with and without a valid Traceparent header. You will see that all requests without a valid Traceparent header are collected and sent to the configured exporter. Ones with a valid Traceparent header are not recorded.
What is the expected behavior?
When the Traceparent header is set, the first span created in the context will have the specified id and everything else works as expected otherwise.
What is the actual behavior?
When the Traceparent header is present, the TraceContextTextMapPropagator sets the context span to a NonRecordingSpan (see here) and the request-related spans are not recorded/exported.
Disabling the use of the TraceContextTextMapPropagator (for example, by setting OTEL_PROPAGATORS=baggage in the environment) fixes the non-recording problem, but then the Traceparent header is also ignored.
Additional context
It looks like this issue can be fixed in a variety of ways and I'm surprised this issue hasn't been already reported. It very well may be that I'm just missing something.
The key parts are involved are:
TraceContextTextMapPropagator.extract(here) - Not changed in any meaningful way in 4+ yearsopentelemetry.instrumentation.utils. _start_internal_or_server_span(here) - Used frequently and not changed since 2022.
For now, we are just disabling the TraceContextTextMapPropagator in our apps.
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 behavior with FlaskInstrumentor and a valid versus missing Traceparent header, then read TraceContextTextMapPropagator.extract in opentelemetry-api/src/opentelemetry/trace/propagation/tracecontext.py and _start_internal_or_server_span in the instrumentation utilities. Determine how extraction and server-span creation interact. Done means valid Traceparent requests retain their parent ID while request spans remain recording and are exported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100