Tracing
Pick the tracing path that fits your application. Auto-instrumentation is the recommended path for most users.- Auto-instrumentation
- OpenTelemetry
To trace LlamaIndex calls without modifying your application code, call If you only want LlamaIndex traced (not OpenAI, Anthropic, or other supported libraries), call
auto_instrument() at startup. This also enables Braintrust’s instrumentation for any other supported AI libraries your app uses (OpenAI, Anthropic, LiteLLM, etc.).Setup
Install the Braintrust SDK and LlamaIndex, then configure your environment.1
Install dependencies
2
Set environment variables
.env
Trace your application
Callauto_instrument() once at startup; every LLM, embedding, and query engine call is traced automatically.setup_llamaindex() instead. It enables the same dispatcher-based tracing but doesn’t touch other integrations:What Braintrust traces
Braintrust captures:- LLM call spans (e.g.,
OpenAI,Anthropic), with prompt or message list input, response output (role and content for chat, text for completion), and metadata (class, model, temperature, max_tokens) - Embedding spans (e.g.,
OpenAIEmbedding), with input text - Query engine spans (e.g.,
RetrieverQueryEngine), with query input, response text, and source nodes (score, text, node ID, metadata) - Node parser spans (e.g.,
SentenceSplitter), with input documents - Agent, workflow, and tool spans
- Errors on any span, recorded as
<ExceptionType>: <message>
Token usage and streaming response output are not captured on LlamaIndex spans. LlamaIndex is an orchestration layer; token counts appear on the underlying provider span (e.g., OpenAI) to avoid double-counting, and streaming chunks are captured downstream by the provider integration.