Skip to main content
LlamaIndex is a data framework for building LLM-powered applications over external data. Braintrust traces LlamaIndex LLM calls, embeddings, query engines, and agent and workflow runs.
Braintrust offers two ways to trace LlamaIndex: auto-instrumentation, the recommended path for most users, and an OpenTelemetry pipeline.

Auto-instrumentation

To trace LlamaIndex calls without modifying your application code, 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

Call auto_instrument() once at startup; every LLM, embedding, and query engine call is traced automatically.
If you only want LlamaIndex traced (not OpenAI, Anthropic, or other supported libraries), call setup_llamaindex() instead. It enables the same dispatcher-based tracing but doesn’t touch other integrations:

What Braintrust traces

Braintrust captures:
  • Task spans for LLM calls (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, provider)
  • 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
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. For the same reason, LlamaIndex LLM calls are typed as task spans rather than LLM spans, so the underlying provider integration owns the LLM span and duplicate span nesting is avoided.

OpenTelemetry

To trace LlamaIndex calls via OpenTelemetry, attach Braintrust’s span processor to an OTel tracer provider and instrument LlamaIndex with the OpenInference instrumentor. This path is useful when you already have an OpenTelemetry pipeline or want to send the same traces to multiple backends.

Setup

Install LlamaIndex along with the Braintrust OTel extras and the OpenInference LlamaIndex instrumentor, then configure your environment. BRAINTRUST_PARENT associates OTel traces with a Braintrust project.
1

Install dependencies

2

Set environment variables

.env

Trace your application

Attach BraintrustSpanProcessor to an OTel TracerProvider, then instrument LlamaIndex with LlamaIndexInstrumentor from the OpenInference package.
LlamaIndexInstrumentor emits OpenInference-conventioned spans for every LlamaIndex operation. BraintrustSpanProcessor handles auth and routing, so the standard Braintrust environment variables (BRAINTRUST_API_KEY, BRAINTRUST_PARENT, optionally BRAINTRUST_API_URL) are all you need.

What Braintrust traces

LlamaIndexInstrumentor emits OpenTelemetry spans for each instrumented LlamaIndex operation, following OpenInference semantic conventions. Braintrust receives them via OTLP and maps them onto its trace model:
  • LLM call spans get structured input, output, and token metrics
  • Embedding, retrieval, tool, and chain spans preserve their OpenInference attributes as raw fields in metadata
  • Errors are captured from OTel exception events

Resources