OpenAI Agents SDK

Turn OpenAI Agents SDK traces into OpenTelemetry GenAI spans with the OpenTelemetry instrumentation, then add an owner and approvals with telumin-otel.

Python

Package: opentelemetry-instrumentation-openai-agents-v2 (tested with 0.1.0)

bash
pip install opentelemetry-sdk==1.45.2 opentelemetry-instrumentation-openai-agents-v2==0.1.0 openai-agents==0.25.0
Setup (from examples/instrumentation/python-openai-agents)
from agents import Agent, Runner, function_tool, set_trace_processors
from agents.tool_context import ToolContext
from opentelemetry import trace
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from telumin_otel import owner_resource, record_approval

AGENT_NAME = "refund-agent"
AGENT_ID = "refund-agent-v1"

# 1. Tracer provider: the owner goes on the resource (C2), spans go to a file.
provider = TracerProvider(
    resource=Resource.create({"service.name": "refund-service", **owner_resource("payments-team")})
)
# This example writes a file; in production use BatchSpanProcessor(OTLPSpanExporter()).
provider.add_span_processor(SimpleSpanProcessor(OtlpJsonFileExporter(sys.argv[1])))

# 2. Replace the SDK's default trace processor (it uploads to OpenAI) before instrumenting,
#    then bridge Agents SDK traces to OTel GenAI spans. agent_name/agent_id name the run's
#    root invoke_agent span too (C1). No prompt or response content is recorded.
set_trace_processors([])
OpenAIAgentsInstrumentor().instrument(
    tracer_provider=provider,
    agent_name=AGENT_NAME,
    agent_id=AGENT_ID,
    capture_message_content=False,
)
Record the approval in the tool (from examples/instrumentation/python-openai-agents)
def ask_human(amount: int) -> tuple[str, str]:
    """Stand-in for your approval step (a review queue, a chat button, ...)."""
    return ("approved", "refund under the team limit") if amount <= 100 else ("rejected", "over the limit")


@function_tool
def issue_refund(ctx: ToolContext, order_id: str, amount: int) -> str:
    """Refund an order. A person must approve every refund."""
    decision, reason = ask_human(amount)
    # The tool runs inside its execute_tool span, so the decision lands on that span (C4).
    record_approval(
        trace.get_current_span(), decision, "alice@example.com", reason=reason, tool_call_id=ctx.tool_call_id
    )
    return f"refund {decision} for {order_id}"
  • Pass agent_name and agent_id: without them the run's root invoke_agent span has no name and C1 shows red.
  • The package sets no agent version, so C1 shows amber.
  • capture_message_content=False keeps prompts and responses out of the spans.

Runnable example, tested in CI

examples/instrumentation/python-openai-agents runs offline with a mocked model, writes OTLP JSON, and goes through the check on every change. Result: C1 amber, C2 green, C3 green, C4 green (one approval recorded with record_approval).

TypeScript

Package: @arizeai/openinference-instrumentation-openai-agents (version at time of writing: 0.3.5, not yet tested by us)

Not yet tested by us: the install line and setup below have not been run by us.

Not yet tested by us
npm install --save-exact @arizeai/openinference-instrumentation-openai-agents@0.3.5 @openai/agents@0.22.0
Setup (not yet tested by us)
import * as agents from "@openai/agents"
import { OpenAIAgentsInstrumentation } from "@arizeai/openinference-instrumentation-openai-agents"

// After registering your tracer provider (resource with "telumin.agent.owner"):
const instrumentation = new OpenAIAgentsInstrumentation({ tracerProvider: provider })
instrumentation.manuallyInstrument(agents)  // replaces the SDK's own trace processors
  • This package emits OpenInference attributes; the check converts them with its OpenInference mapping, which has no agent id or version.

Example pending

No example yet. Each example must run in CI with a mocked model, without an API key and without network access, and that has not been verified for this package.

Owner and approvals

No instrumentation package records who owns an agent or who approved a tool call. Add both with telumin-otel, as the examples do.

Check the result

To check the result, export the spans as OTLP JSON (or send them through the collector tap) and drop the file on the free check. The check runs in your browser tab.

Guides