LlamaIndex

Braintrust traces LlamaIndex applications via OpenTelemetry.

This integration uses Braintrust's Python SDK configuration for OpenTelemetry.

uv add braintrust[otel] llama-index openai python-dotenv

To trace LlamaIndex spans with Braintrust, configure these environment variables:

.env
BRAINTRUST_API_KEY=your-api-key
BRAINTRUST_PARENT=project_name:llamaindex-demo
OPENAI_API_KEY=your-openai-key

When you create your LlamaIndex application, configure the global handler to send traces to Braintrust:

llamaindex_braintrust.py
import os
 
import llama_index.core
from dotenv import load_dotenv
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai import OpenAI
 
load_dotenv()
 
# Configure LlamaIndex to send OTel traces to Braintrust
# Note: "arize_phoenix" is LlamaIndex's OTel handler name.
# We redirect it to Braintrust by overriding the endpoint.
braintrust_api_url = os.environ.get("BRAINTRUST_API_URL", "https://api.braintrust.dev")
llama_index.core.set_global_handler("arize_phoenix", endpoint=f"{braintrust_api_url}/otel/v1/traces")
 
# Your LlamaIndex application code
messages = [
    ChatMessage(role="system", content="Speak like a pirate. ARRR!"),
    ChatMessage(role="user", content="What do llamas sound like?"),
]
result = OpenAI().chat(messages)
print(result)

On this page

LlamaIndex - Docs - Braintrust