To enable tracing in Phoenix for LangGraph applications running asynchronously (e.g., with `graph.astream()`), you must instrument your application using the OpenInference LangChain instrumentor, which supports both standard LangChain and LangGraph agents. Install the required packages, set your Phoenix endpoint, and use the `register` function to connect your app to Phoenix. Then, instrument with `LangChainInstrumentor().instrument(tracer_provider=tracer_provider)`. This setup will capture spans for agent invocations, including those in streaming mode, and send them to Phoenix for observability and evaluation.
However, there are known issues with context propagation in async streaming (e.g., with `astream_events`), which may cause span retrieval helpers like `get_current_span()` to return `None` or empty lists. This is due to limitations in how context is managed across async boundaries, not a lack of tracing support. Traces should still be collected, but span context helpers may not work as expected in all async scenarios. For best results, ensure you pass the appropriate config when invoking chains asynchronously (e.g., with `ainvoke(prompt, config=config)`) to maintain trace hierarchy. See the links below for setup and known async caveats.
Would you like a step-by-step code example for this setup?
Sources:
- <https://arize.com/docs/phoenix/integrations/frameworks/langgraph/langgraph-tracing|LangGraph Tracing | Phoenix Docs>
- <https://github.com/Arize-ai/phoenix/blob/main/docs/section-integrations/frameworks/langgraph/langgraph-tracing.md|LangGraph Tracing | GitHub Docs>
- <https://github.com/Arize-ai/openinference/issues/1304|Async context propagation issue>
- <https://github.com/Arize-ai/phoenix/issues/6613|Async trace hierarchy fix>