Skip to main content

Splunk OpenTelemetry OpenAI Agents instrumentation

Project description

pypi

This library provides the official OpenTelemetry instrumentation for the openai-agents SDK. It converts the rich trace data emitted by the Agents runtime into the GenAI semantic conventions, enriches spans with request/response payload metadata, and records duration/token usage metrics.

Features

  • Generates spans for agents, tools, generations, guardrails, and handoffs using the OpenTelemetry GenAI semantic conventions.

  • Captures prompts, responses, tool arguments, and system instructions when content capture is enabled.

  • Publishes duration and token metrics for every operation.

  • Supports environment overrides so you can configure agent metadata or disable telemetry without code changes.

Installation

If your application is already configured with OpenTelemetry, install the package and its optional instruments:

pip install opentelemetry-instrumentation-openai-agents-v2
pip install openai-agents

Usage

Instrumentation automatically wires the Agents tracing processor into the SDK. Configure OpenTelemetry as usual, then call OpenAIAgentsInstrumentor.

from agents import Agent, Runner, function_tool
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor


def configure_otel() -> None:
    provider = TracerProvider()
    provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
    trace.set_tracer_provider(provider)

    OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)


@function_tool
def get_weather(city: str) -> str:
    return f"The forecast for {city} is sunny with pleasant temperatures."


assistant = Agent(
    name="Travel Concierge",
    instructions="You are a concise travel concierge.",
    tools=[get_weather],
)

result = Runner.run_sync(assistant, "I'm visiting Barcelona this weekend. How should I pack?")
print(result.final_output)

Configuration

The instrumentor exposes runtime toggles through keyword arguments and environment variables:

  • OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT or OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_CONTENT – controls how much message content is captured. Valid values map to opentelemetry.instrumentation.openai_agents.ContentCaptureMode (span_only, event_only, span_and_event, no_content).

  • OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_METRICS – set to false to disable duration/token metrics.

  • OTEL_INSTRUMENTATION_OPENAI_AGENTS_SYSTEM – overrides the gen_ai.system attribute when your deployment is not the default OpenAI platform.

You can also override agent metadata directly when calling OpenAIAgentsInstrumentor().instrument(...) using agent_name, agent_id, agent_description, base_url, server_address, and server_port.

Examples

The examples directory contains runnable scenarios, including:

  • examples/manual – manual OpenTelemetry configuration for a single agent run.

  • examples/content-capture – demonstrates span and event content capture.

  • examples/zero-code – end-to-end setup using environment configuration only.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file splunk_otel_instrumentation_openai_agents-0.1.0.tar.gz.

File metadata

File hashes

Hashes for splunk_otel_instrumentation_openai_agents-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2f31dbbe3c382206733fa96f08e54af79dfd4c507d523ce111921bbe4ed319a
MD5 b359f9a0cdd1f2404530744bef24f5e6
BLAKE2b-256 ff46f0ae097937defd6cdd0f99e709c3bd1f2292bae746d9a2faddd0a281e528

See more details on using hashes here.

File details

Details for the file splunk_otel_instrumentation_openai_agents-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for splunk_otel_instrumentation_openai_agents-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 880838883b356acca0e3e0e62e8b9fdc50564cdd9a4fb7eb0f2bfc1d39a18049
MD5 4214afcc7e8bb28b011abb96ede121dc
BLAKE2b-256 ea3e51927f62f03375bc0bf559a85b79b4edbed479ce17f432764c23be18d892

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page