Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node_modules
/libpeerconnection.log
npm-debug.log
yarn-error.log
.yarn/
testem.log
/typings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,32 @@
class OpenAIAgentsInstrumentor(BaseInstrumentor):
"""An instrumentor for OpenAI Agents SDK."""

def __init__(self, *, clear: bool = False) -> None:
"""Initialize the instrumentor.

Args:
clear: If True, existing trace processors are dropped
and this instrumentor's processor is set as the only one.
This is useful for replacing the default OpenAI instrumentation
(enabled by default) with this one.
"""
# base class BaseInstrumentor is an ABC without __init__
self._clear: bool = clear

def instrumentation_dependencies(self) -> Collection[str]:
return _instruments

def _instrument(self, **kwargs):
def _instrument(self, **kwargs) -> None:
"""Instruments OpenAI Agents SDK.
Copy link
Member

Choose a reason for hiding this comment

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

please remove redundant comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The full docstring added here is

        """Instruments OpenAI Agents SDK.

        Args:
            tracer_provider: An optional TracerProvider to use
                when creating a Tracer.
            meter_provider: An optional MeterProvider to use
                when creating a Meter.

            Additional kwargs are ignored.
        """

This tells users what arguments are accepted and used for the instrument() call and what arguments are ignored. I think this important information for users. I had to read the full implementation to get this information and decide how we should instrument it.

If insist I'm fine with removing it of course.


Args:
tracer_provider: An optional TracerProvider to use
when creating a Tracer.
meter_provider: An optional MeterProvider to use
when creating a Meter.

Additional kwargs are ignored.
"""
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, __version__, tracer_provider)

Expand All @@ -30,12 +52,15 @@ def _instrument(self, **kwargs):

# Use hook-based approach with OpenAI Agents SDK callbacks
try:
from agents import add_trace_processor
from agents import add_trace_processor, set_trace_processors
from ._hooks import OpenTelemetryTracingProcessor

# Create and add our OpenTelemetry processor
otel_processor = OpenTelemetryTracingProcessor(tracer)
add_trace_processor(otel_processor)
if self._clear:
set_trace_processors([otel_processor])
else:
add_trace_processor(otel_processor)

except Exception:
# Silently handle import errors - OpenAI Agents SDK may not be available
Expand Down