Framework guide

LlamaIndex

Record LlamaIndex model calls as SupaTrace events from Python.

Python SDK: Beta. JavaScript SDK: Coming soon. pip install supatrace==0.1.0 (alpha, Python 3.10+). The JavaScript package is not published to npm. See SDK availability.

Record a call in source mode Beta

Source mode is the default. It makes no network request. The SDK checks your events against the server's batch rules and writes one file to a local spool for you to review. The example records the model name and token counts, not the prompt or reply.

pip install supatrace==0.1.0
import datetime
import supatrace
from llama_index.llms.openai import OpenAI

trace = supatrace.init(service="support-bot", spool="./spool")
now = lambda: datetime.datetime.now(datetime.timezone.utc).isoformat()

started = now()
reply = OpenAI(model="YOUR_MODEL").complete("Say hello.")
result = trace.batch([
    {"id": "req-1", "time": started, "kind": "request", "name": "OpenAI.complete", "data": {"model": "YOUR_MODEL"}},
    {"id": "res-1", "time": now(), "kind": "response", "name": "OpenAI.complete", "data": {"output_chars": len(reply.text)}},
])
print(result["report"]["valid"], result["report"]["path"])

Review, then upload

Read the spooled file. Remove anything you do not want stored. Then upload it as shown in the quickstart. Batch limits apply.

Automatic spans over OTLP Beta

With mode="otlp" the Python SDK registers the openinference-instrumentation-llama-index instrumentor when it is installed and exports spans to SUPATRACE_OTLP_ENDPOINT + /v1/traces, authenticated with your write key. Framework instrumentation has local tests but no hosted acceptance proof. For a first trace, use a stock exporter from the OpenTelemetry guide. LlamaIndex is not in the default instrument list; name it in instruments.

pip install "opentelemetry-sdk>=1.27" "opentelemetry-exporter-otlp-proto-http>=1.27" openinference-instrumentation-llama-index
export SUPATRACE_OTLP_ENDPOINT="https://supatrace.dev"   # SupaTrace SDK OTLP mode (Python Beta; JavaScript source only)
export SUPATRACE_API_KEY="YOUR_WRITE_KEY"
import supatrace

trace = supatrace.init(service="support-bot", mode="otlp", instruments=["llama_index"])
print(trace.capture["sending"], trace.capture["instrumented"], trace.capture["skipped"])

Nothing is sent unless the endpoint, the key and the OpenTelemetry packages are all present. When one is missing, trace.capture["skipped"] says which. Prompt and response content is not captured unless you pass capture_content=True or set SUPATRACE_CAPTURE_CONTENT=1.