Docs menu

Python

Three ways in, from least to most code. All of them export OTLP over HTTP to https://api.trazadb.com with an ingest key.

OpenLLMetry: instrument the libraries you already use

OpenLLMetry instruments the OpenAI, Anthropic and other model SDKs, LangChain, LlamaIndex and vector stores, and records prompts and completions in the attributes Traza reads.

pip install traceloop-sdk
export TRACELOOP_BASE_URL=https://api.trazadb.com
export TRACELOOP_HEADERS="Authorization=Bearer%20$TRAZA_API_KEY"
from traceloop.sdk import Traceloop

Traceloop.init(app_name="support-agent")

def handle(conversation_id: str, question: str) -> str:
    # Every span recorded from here on belongs to this run.
    Traceloop.set_association_properties({"session_id": conversation_id})
    ...

app_name becomes the service name, which is what Guard policies match. session_id arrives as traceloop.association.properties.session_id, one of the session keys Traza recognizes.

OpenInference

The OpenInference instrumentations work the same way with a standard OpenTelemetry tracer provider. Use the provider below, then for example:

pip install openinference-instrumentation-openai
from openinference.instrumentation import using_session
from openinference.instrumentation.openai import OpenAIInstrumentor

OpenAIInstrumentor().instrument(tracer_provider=provider)

with using_session(session_id="sess-42"):
    ...  # model calls here carry session.id

The OpenTelemetry SDK directly

pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
import os
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

provider = TracerProvider(resource=Resource.create({"service.name": "support-agent"}))
provider.add_span_processor(
    BatchSpanProcessor(
        OTLPSpanExporter(
            endpoint="https://api.trazadb.com/v1/traces",
            headers={"Authorization": f"Bearer {os.environ['TRAZA_API_KEY']}"},
        )
    )
)
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("support-agent")

with tracer.start_as_current_span("search_orders.tool") as span:
    span.set_attribute("session.id", "sess-42")
    span.set_attribute("gen_ai.operation.name", "execute_tool")
    span.set_attribute("gen_ai.tool.name", "search_orders")
    span.set_attribute("gen_ai.tool.call.arguments", '{"order_id": "1042"}')

gen_ai.operation.name decides what kind of step a span is (chat for a model call, execute_tool for a tool, invoke_agent for an agent), which is what Guard counts. The exporter’s explicit endpoint is the full traces URL; only the environment variable form appends /v1/traces.

Call provider.shutdown() before a short-lived script exits, or the last batch is never sent.

Zero code

opentelemetry-instrument from opentelemetry-distro reads the standard environment variables from the overview, so an already instrumented app needs no code change at all.