Replies: 1 comment
-
The order matters. So here is the implementation to inject the class InjectTraceParentIntoResponseMiddleware(BaseHTTPMiddleware):
def __init__(self, app: ASGIApp):
super().__init__(app)
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
response: Response = await call_next(request)
scope = {}
inject(scope)
for key, value in scope.items():
response.headers.append(key, value)
return response main.py app = FastAPI()
app.add_middleware(InjectTraceParentIntoResponseMiddleware)
FastAPIInstrumentor.instrument_app(app, tracer_provider=tracer_provider) |
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
-
I'm trying to return the trace data to the client, so the client can send it back in next requests, as part of an workflow use case. There are 4 requests that should be grouped into the same trace.
Middleware
never gets the current span - it's alwaysInvalid_Span
instance.Middleware
main
The traces are being collected fine. I can see them in the dashboard (see screenshot), but my middleware don't the the current span, it looks like it's "closed" or something else.
And as you can see, I'm adding my middleware after the FastAPI instrumentation middleware.
Beta Was this translation helpful? Give feedback.
All reactions