Skip to content

Conversation

nagkumar91
Copy link

@nagkumar91 nagkumar91 commented Sep 16, 2025

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Test Summary

  • Unit tests: Runs tests/test_openai_agents.py and tests/test_utils.py to verify instrumentor lifecycle (instrument()/uninstrument()), dependency reporting, and env-driven config
    (capture content and metrics on/off).
  • Example exercise: Executes examples/basic_usage.py to validate end‑to‑end agent tracing, span naming, and metric recording with a real tracer/exporter.
  • Config toggles: Validates behavior under OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_CONTENT=true and OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_METRICS=false, plus default settings.
  • Import wiring: Confirms OpenAIAgentsInstrumentor registers GenAISemanticProcessor via agents.tracing.add_trace_processor when openai-agent is present.

Reproduction Steps

  • Create venv (Python 3.11+ required due to openai-agent):
    • python3.11 -m venv .venv && source .venv/bin/activate
    • pip install -U pip wheel
  • Install package and deps:
    • pip install -e .
    • pip install 'openai-agent>=0.1.0' 'opentelemetry-api~=1.30' 'opentelemetry-sdk~=1.30' 'opentelemetry-instrumentation~=0.51b0' 'opentelemetry-semantic-conventions~=0.51b0'
    • Optional for examples: pip install azure-monitor-opentelemetry python-dotenv openai
  • Run unit tests:
    • python -m unittest -v tests/test_openai_agents.py tests/test_utils.py
    • With toggles:
    • OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_CONTENT=true python -m unittest -v tests/test_openai_agents.py
    • OTEL_INSTRUMENTATION_OPENAI_AGENTS_CAPTURE_METRICS=false python -m unittest -v tests/test_openai_agents.py
  • Run example (optional):
    • Export: APPLICATION_INSIGHTS_CONNECTION_STRING, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION, AZURE_OPENAI_API_KEY
    • python examples/basic_usage.py (observe spans/metrics in Azure Monitor). For non‑Azure setups, initialize the OTel SDK with an OTLP exporter and run the same script.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@nagkumar91 nagkumar91 requested a review from a team as a code owner September 16, 2025 21:16
Copy link

linux-foundation-easycla bot commented Sep 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@nagkumar91 nagkumar91 marked this pull request as draft September 16, 2025 21:53
@nagkumar91 nagkumar91 marked this pull request as ready for review September 25, 2025 18:02
:target: https://pypi.org/project/opentelemetry-instrumentation-openai-agents/

This library allows tracing OpenAI Agents framework requests and logging of messages made by the
`OpenAI Python API library <https://pypi.org/project/openai/>`_ when used with agent frameworks.
Copy link
Contributor

@lzchen lzchen Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure which library this instrumentor instruments. Is it openai or openai-agents?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a question to bring up to the SIG is if we would want this instrumentation to be standalone or included as part of openai instrumentation


OpenAIAgentsInstrumentor().instrument()

custom_client = AsyncAzureOpenAI(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would treat this as separate azureopenai example. We would also want a more generic example with just OpenAI client.

@@ -0,0 +1,59 @@
# OpenAI Agents Instrumentation Examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently all other genai instrumentations have a manual and zerocode examples. Perhaps we can follow up with a separate pr for zerocode. https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples

def _uninstrument(self, **kwargs):
"""Uninstruments the OpenAI library for agent frameworks."""
# No-op: optional processor registry may not be present.
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can maintain the old list of processors and restore it upon _uninstrument.

tracer_provider,
schema_url=Schemas.V1_28_0.value,
)
event_logger_provider = kwargs.get("event_logger_provider")
Copy link
Contributor

@lzchen lzchen Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabmass @DylanRussell @xrmx

What is our stance on adding net new components that rely on the soon-to-be deprecated events api/sdk?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I believe it should just use logs directly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we are deprecating it still. The current hangup is over what the exact signature(s) for logger.emit should look like. open-telemetry/opentelemetry-python#4737 -- if one of y'all could chime in on that it would be helpful to move this along.. I provided my opinion already

nagkumar91 and others added 19 commits September 26, 2025 11:01
…m most; add enhanced_travel_planner and trace_collectors; update README
…mode returning [{"type":"text","content":"readacted"}] when sensitive capture disabled; add TODO to restore processors on uninstrument
@@ -0,0 +1,135 @@
"""Centralized semantic convention constants for GenAI instrumentation.
Copy link
Contributor

@xrmx xrmx Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should being able to import these from semantic conventions package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants