Anyone have an example to follow of instrumenting a fastapi app with langgraph workflows. Utilizing custom decorators? Its kinda complicated to pass down the root span in order to connect everything manually for each endpoint. I utilize a stream response output too.
To instrument a FastAPI app with LangGraph workflows and custom decorators, use the OpenInference LangChain instrumentor, which supports LangGraph out of the box. Set up tracing with phoenix.otel.register and auto-instrumentation, so spans are created for each agent invocation and streamed to Phoenix. For streaming responses, you must manually propagate the parent span context into the async generator to maintain trace hierarchy鈥攖his is a known OpenTelemetry limitation in async/streaming scenarios. See the linked example for context propagation in streaming endpoints.For custom decorators, you can use the tracer's decorator (e.g., @tracer.chain) to wrap functions, but if you need to set dynamic attributes or handle streaming, you should use a with tracer.start_as_current_span(...) block inside your endpoint and manually manage the span context in your generator. See the code example and discussion in the sources for details on both approaches and context propagation in streaming FastAPI endpoints with LangGraph and Phoenix.Would you like a step-by-step code example for this setup?Sources:
- Streaming context propagation example
- Phoenix tracing with custom decorators
馃挕聽Hint: Mention RunLLM in the thread for followups.
