LlamaIndex

Retrievers, query engines, and chat engines produce a span tree with retrieval and LLM children.

Install the instrumentor alongside llama-index and every retriever, query, and chat call inside wrap your agent emits spans. LlamaIndex is Python-first; a Node instrumentor (@opentelemetry/instrumentation-llamaindex) is also available.

What's captured

ConstructSpan kindAuto-extracted
VectorIndexRetriever.retrieveretrievalquery, doc count, doc ids
QueryEngine.queryagentwraps retrieval + synthesis
ChatEngine.chatagentwraps retrieval + LLM + memory
ResponseSynthesizerllmmodel, tokens
Embeddingsllmmodel, tokens

Install

pip install llama-index opentelemetry-instrumentation-llamaindex

Minimal example — RAG query

import os, trodo
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

trodo.init(site_id=os.environ['TRODO_SITE_ID'])

documents = SimpleDirectoryReader('./docs').load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()

with trodo.wrap_agent('llamaindex-rag') as run:
    run.set_input({'q': 'What is HNSW?'})
    response = query_engine.query('What is HNSW?')
    run.set_output(str(response))

The resulting tree nests retrieval and the LLM synthesis under one agent span:

run (wrap_agent)
 └─ agent       QueryEngine.query
      ├─ retrieval   VectorIndexRetriever.retrieve
      └─ llm         ResponseSynthesizer (gpt-4o-mini)

For multi-turn chat engines, pass conversation_id to wrap_agent to stitch turns into a conversation.

On this page