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

> Trace LlamaIndex apps with BotGauge in code or zero-code. Verified versions, install line, and a tested chat sample.

Records LlamaIndex LLM calls and framework spans.

| | |
| - | - |
| Extra | `[llamaindex]` |
| Verified framework versions | llama-index-core 0.14.25 |
| Instrumentor installed by the extra | `openinference-instrumentation-llama-index 4.6.0` |
| Zero-code run | Traced |

Also verified: llama-index-core 0.14.25 with instrumentor 4.5.2. 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[llamaindex]" llama-index-core==0.14.25 llama-index-llms-openai==0.8.3 openai==2.54.0
```

**2. Add the code**

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

from botgauge import tracing
from llama_index.core.base.llms.types import ChatMessage
from llama_index.llms.openai import OpenAI
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor

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

llm = OpenAI(model=os.environ["OPENAI_MODEL"], api_base=os.environ["OPENAI_BASE_URL"])

with tracing.turn(session_id="ses_llamaindex"), tracing.agent("llamaindex-agent"):
    reply = llm.chat([ChatMessage(role="user", content="In one sentence, what is OpenTelemetry?")])
print(reply.message.content)

tracing.shutdown()
```

**3. Run**

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

Needs `BOTGAUGE_API_KEY`, `OPENAI_API_KEY`, `OPENAI_MODEL`, `OPENAI_BASE_URL`.

## 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[llamaindex]" llama-index-core==0.14.25 llama-index-llms-openai==0.8.3 openai==2.54.0
```

**2. Add the code**

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

from botgauge import tracing
from llama_index.core.base.llms.types import ChatMessage
from llama_index.llms.openai import OpenAI

llm = OpenAI(model=os.environ["OPENAI_MODEL"], api_base=os.environ["OPENAI_BASE_URL"])

with tracing.turn(session_id="ses_llamaindex"), tracing.agent("llamaindex-agent"):
    reply = llm.chat([ChatMessage(role="user", content="In one sentence, what is OpenTelemetry?")])
print(reply.message.content)
```

**3. Run**

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

Needs `BOTGAUGE_API_KEY`, `OPENAI_API_KEY`, `OPENAI_MODEL`, `OPENAI_BASE_URL`.

View LlamaIndex spans liveWatch your LlamaIndex LLM and framework 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.