Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asgi request headers are not retrieved properly #307

Closed
garnertan opened this issue Jan 31, 2021 · 0 comments · Fixed by #308
Closed

Asgi request headers are not retrieved properly #307

garnertan opened this issue Jan 31, 2021 · 0 comments · Fixed by #308
Labels
bug Something isn't working

Comments

@garnertan
Copy link
Contributor

Environment:
Python: python3.8

fastapi==0.63.0
opentelemetry-api==0.16b1
opentelemetry-sdk==0.16b1
opentelemetry-instrumentation-fastapi==0.16b1
opentelemetry-exporter-google-cloud==0.16b1
opentelemetry-tools-google-cloud==0.16b1

When using CloudTraceFormatPropagator for GCP, X-Cloud-Trace-Context header cannot be retrieved.

Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.

# server.py
import uvicorn
from fastapi import FastAPI, Request
from opentelemetry import trace
from opentelemetry.propagators import set_global_textmap
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.tools import cloud_trace_propagator

set_global_textmap(cloud_trace_propagator.CloudTraceFormatPropagator())

app = FastAPI()

tracer = trace.get_tracer("test")
FastAPIInstrumentor.instrument_app(app)

@app.get("/trace")
async def test(r: Request):
    with tracer.start_as_current_span("test") as span:
        trace_id = span.get_span_context().trace_id
        print(f"{trace_id:32x}")  # should print trace ID from `X-Cloud-Trace-Context` header value

uvicorn.run(app)
# client.py
import requests

r = requests.Session()
r.headers.setdefault("X-Cloud-Trace-Context",
                        "f3ef5c2ede256aa77491057e600eca11/15104302039794794507;o=1")
r.get("http://localhost:8000/trace")

What is the expected behavior?
Printed value should be f3ef5c2ede256aa77491057e600eca11 based from the header sent

What is the actual behavior?
A newly generated value everything /trace is called

Additional context
X-Cloud-Trace-Context header value is not retrieved properly in CloudTraceFormatPropagator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant