Skip to main content

Install

pip install openai-agents openinference-instrumentation-openai-agents \
            opentelemetry-sdk opentelemetry-exporter-otlp-proto-http

Setup

OpenAI Agents traces can include prompts, completions, handoffs, guardrails, and tool payloads. Review Data Governance before enabling production traffic.
import os
from agents import set_tracing_disabled
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from openinference.instrumentation import using_attributes
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://otel.agnost.ai"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = "X-Agnost-Org-ID=<your-org-id>"

set_tracing_disabled(True)  # turn off OpenAI's hosted trace backend

provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)
OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)

with using_attributes(session_id="sess-123", user_id="u-42"):
    await Runner.run(agent, "Hello")
You get agent / handoff / guardrail spans plus the underlying LLM call spans with full message and tool data (llm.input_messages.*, llm.output_messages.*, tool.name, tool.parameters, llm.token_count.*).

Caveats

Without set_tracing_disabled(True), traces also flow to OpenAI’s hosted dashboard.

Verify

Run one Runner.run call, then open Raw logs in Agnost. Confirm agent, handoff, guardrail, and LLM spans are present.

Troubleshooting

  • Call set_tracing_disabled(True) if you do not want dual-send to OpenAI’s hosted trace backend.
  • Confirm OTEL_EXPORTER_OTLP_HEADERS contains X-Agnost-Org-ID=<your-org-id>.
  • Confirm using_attributes wraps the call you want grouped.

References