LlamaIndex

How to use the python LlamaIndexInstrumentor to trace LlamaIndex

LlamaIndex is a data framework for your LLM application. It's a powerful framework by which you can build an application that leverages RAG (retrieval-augmented generation) to super-charge an LLM with your own data. RAG is an extremely powerful LLM application model because it lets you harness the power of LLMs such as OpenAI's GPT but tuned to your data and use-case.

For LlamaIndex, tracing instrumentation is added via an OpenTelemetry instrumentor aptly named the LlamaIndexInstrumentor . This callback is what is used to create spans and send them to the Phoenix collector.

Phoenix supports LlamaIndex's latest instrumentation paradigm.

To get started, pip install the following.

pip install "llama-index-core>=0.10.43" "openinference-instrumentation-llama-index>=2" "opentelemetry-proto>=1.12.0" arize-phoenix-otel

Use the following code snippet to activate the instrumentation.

Note that the endpoint variable below should the address of the Phoenix receiver.

from openinference.instrumentation.llama_index import LlamaIndexInstrumentor
from phoenix.otel import register

tracer_provider = register(
  project_name="my-llm-app", # Default is 'default'
  endpoint="http://localhost:6006",
)

LlamaIndexInstrumentor().instrument(tracer_provider=tracer_provider)

Note that the legacy One-Click system of spans can still be used instead by setting use_legacy_callback_handler=True as shown below.

LlamaIndexInstrumentor().instrument(
    tracer_provider=tracer_provider,
    use_legacy_callback_handler=True,
)

By adding the callback to the callback manager of LlamaIndex, we've created a one-way data connection between your LLM application and Phoenix Server.

For a fully working example of tracing with LlamaIndex, checkout our colab notebook.

Last updated