OpenTelemetry OpenAI Agents Instrumentation (Alpha)
This package provides OpenTelemetry instrumentation for
OpenAI Agents SDK,
a framework for building agentic AI applications. It leverages Splunk distribution
of opentelemetry-util-genai for producing telemetry in semantic convention.
Core concepts, high-level usage and configuration
Status: Alpha (APIs and produced telemetry are subject to change).
Installation
pip install splunk-otel-instrumentation-openai-agents
Quick Start
Manual Instrumentation (development/debugging)
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from agents import Agent, Runner, function_tool
# manual instrumentation, easy to debug in your IDE
OpenAIAgentsInstrumentor().instrument()
@function_tool
def get_weather(city: str) -> str:
return f"The forecast for {city} is sunny."
agent = Agent(
name="Travel Concierge",
instructions="You are a concise travel concierge.",
tools=[get_weather],
)
result = Runner.run_sync(agent, "How is the weather in Paris?")
print(result.final_output)
Zero-code instrumentation
In zero-code instrumentation mode, ensure you install opentelemetry-distribution and run your app with the OpenTelemetry OpenAI Agents Instrumentor enabled:
opentelemetry-instrument python your_agents_app.py
from agents import Agent, Runner
agent = Agent(
name="Travel Concierge",
instructions="You are a concise travel concierge.",
)
result = Runner.run_sync(agent, "What are top attractions in Tokyo?")
print(result.final_output)
What Gets Instrumented
This instrumentation captures:
- Workflows -> Mapped to
Workflowspans - Agents -> Mapped to
AgentInvocationspans - Tool Calls -> Mapped to
ToolCallspans - Generations -> Mapped to
LLMInvocationspans
All spans are properly nested with correct parent-child relationships and include rich attributes about the operation.
Configuration
Enabling message content
Message content such as prompts, completions, tool arguments, and return values
are not captured by default. To enable content capturing, set the environment variable
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to one of the following values:
true— Legacy. Treated asspan_and_eventfor backward compatibility.span_only— Capture content on span attributes only.event_only— Capture content on event attributes only.span_and_event— Capture content on both span and event attributes.
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=span_and_event
Other environment variables
# Capture tool/function definitions on LLM spans (disabled by default)
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_DEFINITIONS=true
# Disable metrics
export OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_METRICS=false
Backward compatibility: The deprecated
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT_MODEvariable is still honored when the primary variable is set to a truthy value (true/1/yes/on).
Instrumentation Options
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
# Basic instrumentation
OpenAIAgentsInstrumentor().instrument()
# With custom tracer provider
OpenAIAgentsInstrumentor().instrument(tracer_provider=my_tracer_provider)
# Uninstrumentation
OpenAIAgentsInstrumentor().uninstrument()
Requirements
- Python >= 3.10
- openai-agents >= 0.3.3
- OpenTelemetry API >= 1.37
splunk-otel-util-genai>= 0.1.9
Trace Hierarchy Example
Workflow: Travel Planning (Workflow)
└── Agent: Travel Concierge (AgentInvocation)
├── LLM: gpt-4o-mini (Generation)
│ └── gen_ai.choice
├── Tool: get_weather (ToolCall)
└── LLM: gpt-4o-mini (Generation)
└── gen_ai.choice
Each span includes rich attributes:
gen_ai.system= "openai"gen_ai.framework= "openai_agents"gen_ai.operation.name= "invoke_workflow" | "invoke_agent" | "execute_tool" | "chat"- Framework-specific attributes (agent name, tool names, etc.)
Testing
Run the package tests (from repository root or this directory):
pytest instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2/tests
Contributing
Issues / PRs welcome in the main splunk-otel-python-contrib repository. This module is alpha: feedback on attribute coverage, performance, and OpenAI Agents surface expansion is especially helpful.
Links
License
Apache-2.0
Metadata
Release files for splunk-otel-instrumentation-openai-agents 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| splunk_otel_instrumentation_openai_agents-0.1.5.tar.gz | 27.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| splunk_otel_instrumentation_openai_agents-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 56.8 kB
Release files / splunk_otel_instrumentation_openai_agents-0.1.5.tar.gz
| Download URL | splunk_otel_instrumentation_openai_agents-0.1.5.tar.gz |
|---|---|
| Size | 27.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a48340e4656ec661b01f86249257bdde6b2fa80bfaca07c335abb15ce3ef94bc
|
|
BLAKE2b-256 checksum How to use checksums |
d0adcc07dc4e0de3b793cd413837c6d9a345a06c964dd7062d48c02e8e6b6568
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.11.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.11.15","system":{"name":"Linux","release":"5.15.0-1084-aws"}} HTTPX2/2.9.1
|
Release files / splunk_otel_instrumentation_openai_agents-0.1.5-py3-none-any.whl
| Download URL | splunk_otel_instrumentation_openai_agents-0.1.5-py3-none-any.whl |
|---|---|
| Size | 29.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34e78576e51ea2b56e18043d4f270722ba5566ce790641038923405cfacb4445
|
|
BLAKE2b-256 checksum How to use checksums |
50c999bcea4f278413b0700fbd8f597217765aa68a554be54a520a8d767d6fb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.11.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.11.15","system":{"name":"Linux","release":"5.15.0-1084-aws"}} HTTPX2/2.9.1
|