Skip to content

Send LlamaIndex Traces to KloudMate

The OpenInference instrumentation for LlamaIndex creates a span for each agent run, model call, embedding, and tool call. Send those spans to KloudMate to see each run in AI Observability.

Use OpenInference rather than LlamaIndex’s own llama-index-observability-otel package. Its spans don’t use the GenAI attribute names, so model calls and tokens don’t appear in AI Observability.

  • A KloudMate API key, from Settings → Ingest Keys.
  • Python 3.10 or later.

Install the instrumentation and the OpenTelemetry launcher:

pip install openinference-instrumentation-llama-index opentelemetry-distro opentelemetry-exporter-otlp-proto-http

Point the exporter at KloudMate and start your app with opentelemetry-instrument, which loads the LlamaIndex instrumentation automatically:

export OTEL_SERVICE_NAME="rag-service"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otel.kloudmate.com:4318"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=YOUR_KLOUDMATE_API_KEY"

opentelemetry-instrument python app.py

KloudMate expects the raw API key in the Authorization header, with no Bearer prefix. If the KloudMate agent runs on the same machine, set the endpoint to http://localhost:4318 and leave out the header.

Wrap each call in using_session() with an ID that stays the same for the whole conversation:

from openinference.instrumentation import using_session

with using_session("chat-42"):
    response = await agent.run(question)

OpenInference records prompts, responses, and retrieved documents by default. To leave out inputs and outputs, set these variables before your app starts:

export OPENINFERENCE_HIDE_INPUTS="true"
export OPENINFERENCE_HIDE_OUTPUTS="true"

Token counts, models, and latency are still recorded. The OpenInference configuration lists the finer-grained settings, such as OPENINFERENCE_HIDE_RETRIEVAL_DOCUMENTS.

Run a query once, then open AI Observability → Traces. The run appears with its model calls, tokens, and estimated cost.