Skip to content

Commit 822d228

Browse files
committed
docs: add official package metadata
1 parent 10100ee commit 822d228

File tree

2 files changed

+116
-5
lines changed

2 files changed

+116
-5
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
OpenTelemetry OpenAI Agents Instrumentation
2+
===========================================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-openai-agents-v2.svg
7+
:target: https://pypi.org/project/opentelemetry-instrumentation-openai-agents-v2/
8+
9+
This library provides the official OpenTelemetry instrumentation for the
10+
`openai-agents SDK <https://pypi.org/project/openai-agents/>`_. It converts
11+
the rich trace data emitted by the Agents runtime
12+
into the GenAI semantic conventions, enriches spans with request/response payload
13+
metadata, and records duration/token usage metrics.
14+
15+
Features
16+
--------
17+
18+
* Generates spans for agents, tools, generations, guardrails, and handoffs using
19+
the OpenTelemetry GenAI semantic conventions.
20+
* Captures prompts, responses, tool arguments, and system instructions when content
21+
capture is enabled.
22+
* Publishes duration and token metrics for every operation.
23+
* Supports environment overrides so you can configure agent metadata or disable
24+
telemetry without code changes.
25+
26+
Installation
27+
------------
28+
29+
If your application is already configured with OpenTelemetry, install the package
30+
and its optional instruments:
31+
32+
.. code-block:: console
33+
34+
pip install opentelemetry-instrumentation-openai-agents-v2
35+
pip install openai-agents
36+
37+
Usage
38+
-----
39+
40+
Instrumentation automatically wires the Agents tracing processor into the SDK.
41+
Configure OpenTelemetry as usual, then call :class:`OpenAIAgentsInstrumentor`.
42+
43+
.. code-block:: python
44+
45+
from agents import Agent, Runner, function_tool
46+
from opentelemetry import trace
47+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
48+
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
49+
from opentelemetry.sdk.trace import TracerProvider
50+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
51+
52+
53+
def configure_otel() -> None:
54+
provider = TracerProvider()
55+
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
56+
trace.set_tracer_provider(provider)
57+
58+
OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)
59+
60+
61+
@function_tool
62+
def get_weather(city: str) -> str:
63+
return f"The forecast for {city} is sunny with pleasant temperatures."
64+
65+
66+
assistant = Agent(
67+
name="Travel Concierge",
68+
instructions="You are a concise travel concierge.",
69+
tools=[get_weather],
70+
)
71+
72+
result = Runner.run_sync(assistant, "I'm visiting Barcelona this weekend. How should I pack?")
73+
print(result.final_output)
74+
75+
Configuration
76+
-------------
77+
78+
The instrumentor exposes runtime toggles through keyword arguments and environment
79+
variables:
80+
81+
* ``OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT`` or
82+
``OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_CONTENT`` – controls how much
83+
message content is captured. Valid values map to
84+
:class:`opentelemetry.instrumentation.openai_agents.ContentCaptureMode`
85+
(``span_only``, ``event_only``, ``span_and_event``, ``no_content``).
86+
* ``OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_METRICS`` – set to ``false`` to
87+
disable duration/token metrics.
88+
* ``OTEL_INSTRUMENTATION_OPENAI_AGENTS_SYSTEM`` – overrides the ``gen_ai.system``
89+
attribute when your deployment is not the default OpenAI platform.
90+
91+
You can also override agent metadata directly when calling
92+
``OpenAIAgentsInstrumentor().instrument(...)`` using ``agent_name``, ``agent_id``,
93+
``agent_description``, ``base_url``, ``server_address``, and ``server_port``.
94+
95+
Examples
96+
--------
97+
98+
The :mod:`examples` directory contains runnable scenarios, including:
99+
100+
* ``examples/manual`` – manual OpenTelemetry configuration for a single agent run.
101+
* ``examples/content-capture`` – demonstrates span and event content capture.
102+
* ``examples/zero-code`` – end-to-end setup using environment configuration only.
103+
104+
References
105+
----------
106+
107+
* `OpenTelemetry Python Contrib <https://github.com/open-telemetry/opentelemetry-python-contrib>`_
108+
* `OpenTelemetry GenAI semantic conventions <https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/>`_
109+
* `OpenAI Agents SDK <https://github.com/openai/openai-agents-python>`_

instrumentation-genai/opentelemetry-instrumentation-openai-agents-v2/pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ build-backend = "hatchling.build"
55
[project]
66
name = "opentelemetry-instrumentation-openai-agents-v2"
77
dynamic = ["version"]
8-
description = "OpenTelemetry OpenAI Agents instrumentation (barebones)"
8+
description = "OpenTelemetry Official OpenAI Agents instrumentation"
9+
readme = "README.rst"
910
license = "Apache-2.0"
1011
requires-python = ">=3.9"
1112
authors = [
1213
{ name = "OpenTelemetry Authors", email = "[email protected]" },
1314
]
1415
classifiers = [
15-
"Development Status :: 3 - Alpha",
16+
"Development Status :: 4 - Beta",
1617
"Intended Audience :: Developers",
1718
"License :: OSI Approved :: Apache Software License",
1819
"Programming Language :: Python",
@@ -24,9 +25,9 @@ classifiers = [
2425
"Programming Language :: Python :: 3.13",
2526
]
2627
dependencies = [
27-
"opentelemetry-api >= 1.37",
28-
"opentelemetry-instrumentation >= 0.58b0",
29-
"opentelemetry-semantic-conventions >= 0.58b0",
28+
"opentelemetry-api ~= 1.37",
29+
"opentelemetry-instrumentation >=0.58b0, <2",
30+
"opentelemetry-semantic-conventions >=0.58b0, <2",
3031
"opentelemetry-util-genai"
3132
]
3233

@@ -48,6 +49,7 @@ path = "src/opentelemetry/instrumentation/openai_agents/version.py"
4849
[tool.hatch.build.targets.sdist]
4950
include = [
5051
"/src",
52+
"/tests",
5153
]
5254

5355
[tool.hatch.build.targets.wheel]

0 commit comments

Comments
 (0)