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.2.tar.gz.

File metadata

File hashes

Hashes for splunk_otel_instrumentation_openai_agents-0.1.2.tar.gz
Algorithm Hash digest
SHA256 112c038b9a36b3cba8fab65c3c62e52f5a2c44edcdf5d379fa9dde26d9eeef22
MD5 da57801f6b9863cc57eddced7e369901
BLAKE2b-256 7af8884b493756d37c7dfeb8df76dad32531a1b093fa55098642cee29088d41a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splunk_otel_instrumentation_openai_agents-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a64f35134132f0129c11ba2c7acf3444e574f82080db4671eee9317bbfaa8657
MD5 fded9ab6c30ba4dd2f00682fbfeb36db
BLAKE2b-256 3ea674c0a7943484fcd73510861cbfb715fd2d5765e4e8f54c5ddabaab59af65

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