Skip to main content
This example demonstrates how to create and instrument a LlamaIndex query engine with OpenInference tracing.

Prerequisites

  • Python 3.9+
  • OpenAI API key
  • Phoenix or another OpenTelemetry collector

Installation

1

Install dependencies

2

Set environment variables

Instrumentation Setup

First, create an instrumentation module:

Complete Query Engine Example

Chat Engine Example

LlamaIndex also provides chat engines for conversational applications:

Streaming Responses

Key Features

Automatic Tracing

LlamaIndex instrumentation captures:
  • Query execution: Full query pipeline from input to output
  • Retrieval: Document retrieval with similarity scores
  • LLM calls: All calls to language models
  • Embeddings: Embedding generation for queries and documents
  • Node processing: Document chunking and indexing

Resource Attributes

Use resource attributes to organize projects:

Memory and Context

The instrumentation tracks:
  • Conversation history in chat engines
  • Context window management
  • Memory buffer operations

Production Setup

For production deployments:

Next Steps