Skip to main content

OpenTelemetry Official OpenAI Agents instrumentation

Project description

pypi

This library traces applications built with the OpenAI Agents SDK. It registers a tracing processor with the Agents runtime and turns its trace/span callbacks into spans that mirror the structure of your agent run:

  • Workflow spans for an agent run — one per Runner.run / run_sync invocation, named after the run’s RunConfig.workflow_name.

  • Agent spans for each agent invoked within the workflow, including the agent name.

  • Tool spans for function tool calls, capturing the tool arguments and result.

The spans nest to reflect the run, so a single Runner.run produces a workflow span with the agent and tool calls it triggered as children.

LLM-level spans (chat / embeddings) are not emitted by this package. They are produced by opentelemetry-instrumentation-genai-openai when it is installed and instrumented alongside this package.

Installation

pip install opentelemetry-instrumentation-genai-openai-agents

Install opentelemetry-instrumentation-genai-openai as well to also capture the underlying LLM calls.

See the examples directory for runnable manual and zero-code scenarios.

Usage

Call OpenAIAgentsInstrumentor().instrument() once during startup, then run your agent as usual. The Runner.run_sync(...) call below is recorded as a workflow span with the agent and tool spans nested underneath.

from agents import Agent, Runner, function_tool

from opentelemetry.instrumentation.genai.openai_agents import (
    OpenAIAgentsInstrumentor,
)

OpenAIAgentsInstrumentor().instrument()


@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.",
    model="<your-model>",
    tools=[get_weather],
)

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

Configuration

By default the instrumentor keeps the Agents SDK’s built-in trace exporter (which uploads traces to OpenAI’s hosted tracing backend when OPENAI_API_KEY is set) active alongside OpenTelemetry emission. Pass disable_openai_trace_export=True to route traces only through OpenTelemetry:

OpenAIAgentsInstrumentor().instrument(disable_openai_trace_export=True)

The workflow span name comes from the Agents SDK’s own Runner.run(..., run_config=RunConfig(workflow_name=...)) knob. Content capture is controlled through OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable.

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 opentelemetry_instrumentation_genai_openai_agents-1.0b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_genai_openai_agents-1.0b0.tar.gz
Algorithm Hash digest
SHA256 7f8da01fa992b61a35a63cda72bb9bfba05cbeacf97438415543bf42630e10f0
MD5 687b8b79aa3a0877c5e2833c63f1ff0b
BLAKE2b-256 274190257e4f085cd15b8d75ebe0272716e1e35d9358e09316de99185b109169

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_genai_openai_agents-1.0b0.tar.gz:

Publisher: release-all.yml on open-telemetry/opentelemetry-python-genai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opentelemetry_instrumentation_genai_openai_agents-1.0b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_genai_openai_agents-1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 3848374be8f6050f9d698218f12bdd31acac15070a8cde2fd63ac537ceb21e59
MD5 1f07fda6f1d8a3d7625930726ab3b2ec
BLAKE2b-256 4e55959947674959d789b92c4625acc1db1802f201e193cf5f296ec48d45b7fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_genai_openai_agents-1.0b0-py3-none-any.whl:

Publisher: release-all.yml on open-telemetry/opentelemetry-python-genai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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