Replies: 1 comment
-
Don't know if this problem was solved since then, but here's my 2 cents. At least for the part of propagating the context from an incoming request into your FastAPI app, you can do this: from opentelemetry import context, propagate
@app.middleware("http")
async def propagate_context(request: fastapi.Request, call_next):
context.attach(propagate.get_global_textmap().extract(request.headers))
return await call_next(request) Don't forget to also export the environment variable |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there everyone!
Maybe you can share some materials on how to use python auto-instrumentation for context propagation?
I'm working with a quite big number of separate FastAPI services running in docker, and naive
opentelemetry-instrument uvicorn app:app ...
doesn't provide any context propagation.
In result i get a bunch of unrelated traces.
I've succeeded to make a context propagation manually via extracting/injecting trace context from/in headers https://github.com/naumnaum/fastapi-opentelemetry-tracing
However it would be really painful to integrate this manually to the main project i'm working on.
Thanks everyone in advance!
Beta Was this translation helpful? Give feedback.
All reactions