> ## Documentation Index
> Fetch the complete documentation index at: https://www.botgauge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Trace LangGraph with BotGauge

> Trace LangGraph graphs with BotGauge, in code or zero-code. See verified versions, the install line, and a tested supervisor-graph sample.

Records LangGraph graph, node, and LLM spans. LangGraph uses the LangChain instrumentor.

| | |
| - | - |
| Extra | `[langgraph]` |
| Verified framework versions | langgraph 1.2.11 and 1.2.16 |
| Instrumentor installed by the extra | `openinference-instrumentation-langchain 0.1.79` |
| Zero-code run | Traced |

Also verified: langgraph 1.2.11 with instrumentor 0.1.76. The extra no longer installs that older instrumentor. See [supported frameworks](https://www.botgauge.com/docs/integrations/overview.md) for how verification works.

## In code

Call `tracing.init()`, attach the framework instrumentor to the provider it returns, and wrap the work in `tracing.turn()` and `tracing.agent()`.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[langgraph]" langgraph==1.2.16 langchain-openai==1.7.2
```

**2. Add the code**

```python app.py theme={null}
import os

from botgauge import tracing
from langchain_openai import ChatOpenAI
from langgraph.graph import END, START, MessagesState, StateGraph
from openinference.instrumentation.langchain import LangChainInstrumentor

provider = tracing.init()
LangChainInstrumentor().instrument(tracer_provider=provider)

llm = ChatOpenAI(model=os.environ["OPENAI_MODEL"])

def supervisor(state: MessagesState) -> dict:
    return {"messages": [llm.invoke(state["messages"])]}

graph = StateGraph(MessagesState)
graph.add_node("supervisor", supervisor)
graph.add_edge(START, "supervisor")
graph.add_edge("supervisor", END)
app = graph.compile()

with tracing.turn(session_id="ses_langgraph"), tracing.agent("supervisor-graph"):
    result = app.invoke({"messages": [("user", "In one sentence, what is OpenTelemetry?")]})
print(result["messages"][-1].text)

tracing.shutdown()
```

**3. Run**

```bash terminal theme={null}
python app.py
```

Needs `BOTGAUGE_API_KEY`, `OPENAI_API_KEY`, `OPENAI_MODEL`. Set `OPENAI_BASE_URL` too if your LLM isn't api.openai.com.

## Zero-code

Leave your app unchanged and start it with `botgauge instrument`. The sample still wraps the work in `tracing.turn()` and `tracing.agent()` so spans carry session and agent ids.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[langgraph]" langgraph==1.2.16 langchain-openai==1.7.2
```

**2. Add the code**

```python app.py theme={null}
import os

from botgauge import tracing
from langchain_openai import ChatOpenAI
from langgraph.graph import END, START, MessagesState, StateGraph

llm = ChatOpenAI(model=os.environ["OPENAI_MODEL"])

def supervisor(state: MessagesState) -> dict:
    return {"messages": [llm.invoke(state["messages"])]}

graph = StateGraph(MessagesState)
graph.add_node("supervisor", supervisor)
graph.add_edge(START, "supervisor")
graph.add_edge("supervisor", END)
app = graph.compile()

with tracing.turn(session_id="ses_langgraph"), tracing.agent("supervisor-graph"):
    result = app.invoke({"messages": [("user", "In one sentence, what is OpenTelemetry?")]})
print(result["messages"][-1].text)
```

**3. Run**

```bash terminal theme={null}
botgauge instrument python app.py
```

Needs `BOTGAUGE_API_KEY`, `OPENAI_API_KEY`, `OPENAI_MODEL`. Set `OPENAI_BASE_URL` too if your LLM isn't api.openai.com.

View LangGraph spans liveWatch your LangGraph graph, node, and LLM spans appear in [BotGauge](https://cloud.botgauge.com).

[Try BotGauge →](https://cloud.botgauge.com)

## Related

See [versions not verified](https://www.botgauge.com/docs/integrations/versions-not-verified.md) if you run a different version, [capture and redaction](https://www.botgauge.com/docs/tracing/capture-and-redaction.md) to control exported content, and [troubleshooting](https://www.botgauge.com/docs/tracing/troubleshooting.md) if spans are missing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.