Trace OpenAI Agents SDK runs with OpenTelemetry

The OpenAI Agents SDK traces every run, but by default it uploads those traces to OpenAI. OpenInference's bridge replaces that processor, so the same spans go to Maple over OTLP and each conversation becomes one agent session.

invoke_agent Triage agent 7 spans · 4.21s
DurationStatus
invoke_agent Triage agentsupport-agent
4.21sOk
chat gpt-4.1
1.02sOk
execute_tool transfer_to_billing_agent
4.0msOk
invoke_agent Billing agent
3.15sOk
chat gpt-4.1
880msOk
execute_tool get_invoice
240msOk
chat gpt-4.1
1.99sOk

Example: a triage agent handing off to a billing agent

Quick start

Set up OpenAI Agents SDK

1

Install the bridge

bash
npm install @openai/agents \
  @arizeai/openinference-instrumentation-openai-agents \
  @arizeai/openinference-core @opentelemetry/api @opentelemetry/sdk-node
2

Point the exporter at Maple

bash
export OTEL_SERVICE_NAME=support-agent
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production
export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.maple.dev
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_INGEST_KEY"
3

Register the bridge

typescript
// instrumentation.ts: import it first in your entry point
import * as agents from "@openai/agents"
import { OpenAIAgentsInstrumentation } from "@arizeai/openinference-instrumentation-openai-agents"
import { NodeSDK } from "@opentelemetry/sdk-node"

// Reads OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES and OTEL_EXPORTER_OTLP_*
export const sdk = new NodeSDK()
sdk.start()

// Replaces the SDK's default processor, which uploads traces to OpenAI
new OpenAIAgentsInstrumentation().manuallyInstrument(agents)
4

Run each call inside the conversation's context

typescript
import { setAttributes } from "@arizeai/openinference-core"
import { run } from "@openai/agents"
import { context } from "@opentelemetry/api"

export async function handleMessage(conversationId: string, text: string) {
	const ctx = setAttributes(context.active(), { "gen_ai.conversation.id": conversationId })
	const result = await context.with(ctx, () => run(agent, text))
	return result.finalOutput
}

This is the short path. The full OpenAI Agents SDK guide covers the rest.

Organization in the EU region? Send to https://ingest.eu.maple.dev instead of https://ingest.maple.dev. An ingest key only works in its own region.

What you get

What Maple shows for an Agents SDK app

One session per conversation

The bridge copies gen_ai.conversation.id onto every span of a run. Runs that share it form one session, one turn per run.

Tool calls

Each tool the agent calls is a span with its name, arguments and result, inside the turn that called it.

Tokens on every model call

Each model call carries its input and output token counts. Cost shows as unpriced.

Framework label

Sessions show the framework as OpenAI Agents SDK, so they stay apart from other agents in the same organization.

Next to your services

The spans go through the same OpenTelemetry SDK as your HTTP and database spans, so one trace can hold both.

Python too

The full guide has the Python setup for openai-agents, with using_session in place of context.with.

What is different in the Agents SDK

Do not disable tracing

setTracingDisabled(true) and OPENAI_AGENTS_DISABLE_TRACING stop every span, Maple's included. The bridge already stops the upload to OpenAI.

Tests turn tracing off

With NODE_ENV=test the SDK disables tracing on its own. Call setTracingDisabled(false) in tests that check spans.

One OpenAI instrumentation

If every model call appears twice, another instrumentation of the OpenAI client is also active. Keep one.

통합

다른 통합

오늘 첫 트레이스를 확인하세요.

SDK를 추가하고 OTLP 익스포터를 Maple로 향하게 하면 트레이스가 도착합니다.

maple.dev: OpenTelemetry 위의 옵저버빌리티