> ## 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 LangChain with BotGauge

> Trace LangChain agents with BotGauge, in code or with zero-code launch. Verified LangChain versions, install line, and a tested sample.

Records LangChain LLM calls (model, prompts, token counts) and tool calls.

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

Also verified: langchain 1.3.15 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[langchain]" langchain==1.4.6 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 openinference.instrumentation.langchain import LangChainInstrumentor

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

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

with tracing.turn(session_id="ses_langchain"), tracing.agent("langchain-agent"):
    reply = llm.invoke("In one sentence, what is OpenTelemetry?")
print(reply.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[langchain]" langchain==1.4.6 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

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

with tracing.turn(session_id="ses_langchain"), tracing.agent("langchain-agent"):
    reply = llm.invoke("In one sentence, what is OpenTelemetry?")
print(reply.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 LangChain spans liveWatch your LangChain LLM and tool calls 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.