Skip to content

Send OpenAI Agents SDK Traces to KloudMate

The OpenAI Agents SDK traces every run, but by default it sends those traces to the OpenAI dashboard. The OpenInference instrumentation for the Agents SDK turns them into OpenTelemetry spans instead, so you can send them to KloudMate and see each run in AI Observability.

  • A KloudMate API key, from Settings → Ingest Keys.
  • Python 3.10 or later.
pip install openai-agents openinference-instrumentation-openai-agents opentelemetry-sdk opentelemetry-exporter-otlp-proto-http

Set up a tracer provider and instrument the Agents SDK before you run an agent:

from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.trace import set_tracer_provider

tracer_provider = TracerProvider()
tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
set_tracer_provider(tracer_provider)

OpenAIAgentsInstrumentor().instrument(tracer_provider=tracer_provider)

Call tracer_provider.shutdown() before a script exits, so the last spans are sent.

By default, the instrumentation replaces the SDK’s own trace export, so traces stop going to the OpenAI dashboard. To keep sending to both, pass exclusive_processor=False to instrument().

OTLPSpanExporter() reads the standard OpenTelemetry variables. Set them in the environment that runs your app:

export OTEL_SERVICE_NAME="support-agent"
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"

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.

The Agents SDK’s group_id isn’t exported to OpenTelemetry. Wrap each run in using_session() instead:

from openinference.instrumentation import using_session

with using_session("chat-42"):
    result = await Runner.run(agent, question)

Prompts, responses, and tool arguments are recorded by default. To leave them out, 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.

Run the agent once, then open AI Observability → Traces. The run appears as Agent workflow Turn, or under the name you set with RunConfig(workflow_name=...), with its model, steps, tokens, and estimated cost.