open-telemetry / open-telemetry/opentelemetry-python
X-B3-Sampled: 0 alone does not disable the tracing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 19
Description
Describe your environment
fastapi>=0.70.0
uvicorn[standard]>=0.15.0
opentelemetry-api==1.8.0
opentelemetry-sdk==1.8.0
opentelemetry-exporter-zipkin==1.8.0
opentelemetry-propagator-b3==1.8.0
opentelemetry-instrumentation-fastapi==0.27b0
Steps to reproduce
Start server
from opentelemetry import trace
from opentelemetry.exporter.zipkin.json import ZipkinExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from fastapi import FastAPI
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.propagate import set_global_textmap
from opentelemetry.propagators.b3 import B3MultiFormat
import uvicorn
app = FastAPI()
tracer = trace.get_tracer(__name__)
zipkin_exporter = ZipkinExporter(
endpoint="http://127.0.0.1:9411/api/v2/spans",
)
span_processor = BatchSpanProcessor(zipkin_exporter)
trace_provider = TracerProvider(resource=Resource.create({"service.name": "open-telemetry-test"}))
trace_provider.add_span_processor(span_processor)
trace.set_tracer_provider(trace_provider)
set_global_textmap(B3MultiFormat())
@app.get('/hello')
def hello():
with tracer.start_as_current_span("hello"):
return {'hello': 'there'}
FastAPIInstrumentor.instrument_app(app,tracer_provider=trace_provider)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
Test
import requests
requests.get("http://localhost:8000/hello", headers={'X-B3-Sampled': '0'})
What is the expected behavior?
No trace log to Zipkin
https://github.com/openzipkin/b3-propagation
What is the actual behavior?
Trace still log to Zipkin
Additional context
Zipkin docker image: ghcr.io/openzipkin/zipkin-slim:2.23
If has other B3 headers, X-B3-Sampled': '0' works
import requests
from opentelemetry.sdk.trace import id_generator
requests.get("http://localhost:8000/hello", headers={
'X-B3-TraceId': "{:032x}".format(id_generator.RandomIdGenerator().generate_trace_id()),
'X-B3-ParentSpanId': "{:016x}".format(id_generator.RandomIdGenerator().generate_span_id()),
'X-B3-SpanId': "{:016x}".format(id_generator.RandomIdGenerator().generate_span_id()),
'X-B3-Sampled': '0'
})
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 request against the FastAPI example using only the X-B3-Sampled: 0 header, then compare it with the request containing the other B3 headers. Start by tracing how B3MultiFormat and FastAPIInstrumentor handle incoming headers. Done means a request with X-B3-Sampled: 0 alone produces no trace in Zipkin.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- distributed-systems, observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100