How do I trace a LangGraph agent?
Summary
- Call
mlflow.langchain.autolog()once before you invoke the graph. MLflow Tracing supports LangGraph as an extension of its LangChain integration, so one graph run becomes one trace with nested spans for each step. - A trace records the agent's input and final output plus every intermediate step, such as model calls, tool calls and retrieval, with the inputs, outputs, latency, token usage and cost of each step.
- Don't put
@mlflow.traceon each node as a substitute for autolog. Without autolog, that creates one independent root trace per node instead of a single graph trace. Usemlflow.start_span()inside a node to add child spans. - On Databricks, MLflow is the same open-source MLflow, managed for you. Databricks recommends storing traces in Unity Catalog tables, where schema and table permissions govern access and you can query them with SQL.
- On serverless compute, autologging isn't enabled automatically, so call
mlflow.langchain.autolog()explicitly in your code.
How do I trace a LangGraph agent?
Turn on MLflow's LangChain autologging with mlflow.langchain.autolog(), set an MLflow experiment, and run your graph as usual. MLflow captures the whole graph execution as a single trace and logs it to the active experiment, with spans for the nodes, model calls and tool calls inside it. Add manual spans only where a node does work that autologging can't see, such as a validation step.
Tracing matters because a final answer can't tell you which step of the graph went wrong. A trace shows which node ran, which tool the model picked and what came back.
What is agent tracing?
Agent tracing captures a complete record of every agent execution. In MLflow, a trace holds the initial input and final output, plus each intermediate step with that step's inputs, outputs, latency, token usage and cost. The Databricks docs call tracing "the foundational data layer for agent quality": debugging, evaluation and production monitoring all build on the evidence traces capture.
How to trace a LangGraph agent, step by step
- Install the packages. For development on Databricks, install
mlflow[databricks](version 3.14.0 or later in the current Databricks LangGraph guide) withlanggraph,langchain_coreand the LangChain package for your model. For production deployments, the docs recommend the lightermlflow-tracingpackage, which is "optimized for production use". - Enable autologging and choose an experiment. Call autolog before you invoke the graph:
import mlflow
mlflow.langchain.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/langgraph-tracing-demo")
- Run the graph. Call
graph.invoke(...)as you do today, with no changes to nodes or edges. - Read the trace. In your workspace, open Experiments, select the experiment, and click the Traces tab. Each trace opens to a span tree that follows the agent from the graph to each model call and tool call.
- Add detail where autolog stops. Inside a node or tool, wrap a block in a manual span:
from mlflow.entities import SpanType
with mlflow.start_span(name="import_check", span_type=SpanType.TOOL) as span:
span.set_inputs(imports)
exec(imports)
span.set_outputs("ok")
The node's span then carries child spans that record whether each check passed, with exception details when one fails.
What to look for in LangGraph tracing
| Capability | Why it matters for a LangGraph agent |
|---|---|
| One trace per graph run | Keeps every node of a single invocation in one tree instead of scattered records |
| Spans for model and tool calls | Shows which tool the model chose and what it returned at each step |
| Token usage and cost per step | Explains where an agent spends time and money |
| Manual child spans | Covers custom logic inside a node that autologging can't see |
| Session tags | Groups the traces of a multi-turn conversation for review and evaluation |
| Governed, queryable storage | Lets you keep traces long term, control who sees them, and analyze them with SQL |
| A path to evaluation | Turns traces into evaluation datasets and scored runs, not just debugging logs |
How Databricks approaches LangGraph tracing
MLflow on Databricks is the open-source MLflow, managed and integrated with the platform, so there's no tracking server for you to run. The same mlflow.langchain.autolog() call you'd use against a self-hosted server works in a Databricks notebook or in an application that logs to your workspace.
Traces in Unity Catalog. Databricks recommends storing traces in Unity Catalog tables for new and production workloads. Traces are stored in OpenTelemetry format as Delta tables bound to an MLflow experiment, which stays the UI entry point. You bind the location with trace_location=UnityCatalog(catalog_name=..., schema_name=..., table_prefix=...) in mlflow.set_experiment(). Access then follows Unity Catalog schema and table permissions, and you can query spans with SQL through a SQL warehouse, build AI/BI Dashboards on them, or ask questions in natural language with Genie Code. This setup needs MLflow 3.14 or later, a SQL warehouse and a workspace in a supported region.
One record from debugging to quality. The traces you capture while debugging feed the rest of the agent quality loop: mlflow.genai.evaluate() runs LLM judges and code-based scorers against them, and you can add selected traces to an evaluation dataset stored in Unity Catalog. To group multi-turn conversations, set a session ID on each trace with mlflow.update_current_trace(tags={"mlflow.trace.session": session_id}).
Keys out of code. For production, the LangGraph guide recommends Unity Gateway or Databricks secrets instead of hardcoded API keys.
FAQs
Does LangGraph tracing work with open-source MLflow outside Databricks?
Yes. The MLflow LangGraph guide uses the same mlflow.langchain.autolog() call against a self-hosted tracking server. MLflow also tracks token usage and cost for LangGraph automatically.
Why does every node show up as a separate trace?
You probably decorated node functions with @mlflow.trace without calling autolog. Call mlflow.langchain.autolog() once before invoking the graph, and use mlflow.start_span() inside nodes for extra detail.
Can I trace a LangGraph.js agent?
Yes. MLflow supports LangGraph.js tracing through OpenTelemetry ingestion: you export spans to the MLflow tracking server's /v1/traces path with the experiment ID in a request header.
How do I turn LangGraph tracing off?
Call mlflow.langchain.autolog(disable=True) to stop LangChain and LangGraph tracing, or mlflow.autolog(disable=True) to disable autologging globally.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.