Skip to content

Commit 7c29e96

Browse files
committed
remove debug statements and import LIBRARY_VERSION
1 parent c91d78c commit 7c29e96

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

agentops/instrumentation/openai_agents/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ def get_version() -> str:
2222
from importlib.metadata import version
2323

2424
library_version = version("openai-agents")
25-
logger.debug(f"OpenAI Agents SDK version: {library_version}")
2625
return library_version
2726
except ImportError:
28-
logger.warning("Could not find OpenAI Agents SDK version")
27+
logger.debug("Could not find OpenAI Agents SDK version")
2928
return "unknown"
3029

3130

agentops/instrumentation/openai_agents/instrumentor.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,69 @@
2424
from agentops.logging import logger
2525
from agentops.instrumentation.openai_agents.processor import OpenAIAgentsProcessor
2626
from agentops.instrumentation.openai_agents.exporter import OpenAIAgentsExporter
27+
from agentops.instrumentation.openai_agents import LIBRARY_VERSION
2728

2829

2930
class OpenAIAgentsInstrumentor(BaseInstrumentor):
3031
"""An instrumentor for OpenAI Agents SDK that primarily uses the built-in tracing API."""
31-
32+
3233
_processor = None
3334
_exporter = None
3435
_default_processor = None
35-
36+
3637
def instrumentation_dependencies(self) -> Collection[str]:
3738
"""Return packages required for instrumentation."""
3839
return ["openai-agents >= 0.0.1"]
39-
40+
4041
def _instrument(self, **kwargs):
4142
"""Instrument the OpenAI Agents SDK."""
4243
tracer_provider = kwargs.get("tracer_provider")
43-
44+
4445
try:
4546
# Check if Agents SDK is available
4647
try:
4748
import agents # type: ignore
48-
logger.debug(f"Agents SDK detected, version: {getattr(agents, '__version__', 'unknown')}")
49+
50+
logger.debug(f"OpenAI Agents SDK detected with version: {LIBRARY_VERSION}")
4951
except ImportError as e:
50-
logger.debug(f"Agents SDK import failed: {e}")
52+
logger.debug(f"OpenAI Agents SDK import failed: {e}")
5153
return
52-
54+
5355
self._exporter = OpenAIAgentsExporter(tracer_provider=tracer_provider)
5456
self._processor = OpenAIAgentsProcessor(
5557
exporter=self._exporter,
5658
)
57-
59+
5860
# Replace the default processor with our processor
5961
from agents import set_trace_processors # type: ignore
6062
from agents.tracing.processors import default_processor # type: ignore
63+
6164
# Store reference to default processor for later restoration
6265
self._default_processor = default_processor()
6366
set_trace_processors([self._processor])
6467
logger.debug("Replaced default processor with OpenAIAgentsProcessor in OpenAI Agents SDK")
65-
68+
6669
except Exception as e:
6770
logger.warning(f"Failed to instrument OpenAI Agents SDK: {e}")
68-
71+
6972
def _uninstrument(self, **kwargs):
7073
"""Remove instrumentation from OpenAI Agents SDK."""
7174
try:
7275
# Clean up any active spans in the exporter
73-
if hasattr(self, '_exporter') and self._exporter:
76+
if hasattr(self, "_exporter") and self._exporter:
7477
# Call cleanup to properly handle any active spans
75-
if hasattr(self._exporter, 'cleanup'):
78+
if hasattr(self._exporter, "cleanup"):
7679
self._exporter.cleanup()
77-
80+
7881
# Put back the default processor
7982
from agents import set_trace_processors
80-
if hasattr(self, '_default_processor') and self._default_processor:
83+
84+
if hasattr(self, "_default_processor") and self._default_processor:
8185
set_trace_processors([self._default_processor])
8286
self._default_processor = None
8387
self._processor = None
8488
self._exporter = None
85-
89+
8690
logger.info("Successfully removed OpenAI Agents SDK instrumentation")
8791
except Exception as e:
8892
logger.warning(f"Failed to uninstrument OpenAI Agents SDK: {e}")

0 commit comments

Comments
 (0)