Observability for LangGraph with Opik
Opik provides a seamless integration with LangGraph, allowing you to easily log and trace your LangGraph-based applications. By using the OpikTracer
callback, you can automatically capture detailed information about your LangGraph graph executions during both development and production.
Account Setup
Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Getting Started
Installation
To use the OpikTracer
with LangGraph, you’ll need to have both the opik
and langgraph
packages installed. You can install them using pip:
Configuring Opik
Configure the Opik Python SDK for your deployment type. See the Python SDK Configuration guide for detailed instructions on:
- CLI configuration:
opik configure
- Code configuration:
opik.configure()
- Self-hosted vs Cloud vs Enterprise setup
- Configuration files and environment variables
Using the OpikTracer
You can use the OpikTracer
callback with any LangGraph graph by passing it in as an argument to the stream
or invoke
functions:
Once the OpikTracer is configured, you will start to see the traces in the Opik UI:

Practical Example: Classification Workflow
Let’s walk through a real-world example of using LangGraph with Opik for a classification workflow. This example demonstrates how to create a graph with conditional routing and track its execution.
Setting up the Environment
First, let’s set up our environment with the necessary dependencies:
Creating the LangGraph Workflow
We’ll create a LangGraph workflow with 3 nodes that demonstrates conditional routing:
Executing with Opik Tracing
Now let’s execute the workflow with Opik tracing enabled:
The graph execution is now logged on the Opik platform and can be viewed in the UI. The trace will show the complete execution path through the graph, including the classification decision and the chosen response path.
Logging threads
When you are running multi-turn conversations using LangGraph persistence, Opik will use Langgraph’s thread_id as Opik thread_id. Here is an example below:
Updating logged traces
You can use the OpikTracer.created_traces
method to access the trace IDs collected by the OpikTracer callback:
These can then be used with the Opik.log_traces_feedback_scores
method to update the logged traces.
Advanced usage
The OpikTracer
object has a flush
method that can be used to make sure that all traces are logged to the Opik platform before you exit a script. This method will return once all traces have been logged or if the timeout is reach, whichever comes first.