Skip to content

Commit a18fe1d

Browse files
committed
refactor to fix tests
1 parent 486c140 commit a18fe1d

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

agentops/instrumentation/openai/instrumentor.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,13 @@ def _instrument(self, **kwargs):
185185
tracer_provider = kwargs.get("tracer_provider")
186186
tracer = get_tracer(LIBRARY_NAME, LIBRARY_VERSION, tracer_provider)
187187

188-
# Use our custom wrappers for the Responses API to handle context from OpenAI Agents SDK
188+
for wrap_config in WRAPPED_METHODS:
189+
try:
190+
wrap(wrap_config, tracer)
191+
logger.debug(f"Successfully wrapped {wrap_config} with standard wrapper")
192+
except (AttributeError, ModuleNotFoundError) as e:
193+
logger.debug(f"Failed to wrap {wrap_config}: {e}")
194+
189195
from wrapt import wrap_function_wrapper
190196

191197
try:
@@ -207,19 +213,19 @@ def _instrument(self, **kwargs):
207213
except (AttributeError, ModuleNotFoundError) as e:
208214
logger.debug(f"Failed to wrap Responses API with custom wrapper: {e}")
209215

210-
for wrap_config in WRAPPED_METHODS:
211-
try:
212-
wrap(wrap_config, tracer)
213-
logger.debug(f"Successfully wrapped {wrap_config} with standard wrapper")
214-
except (AttributeError, ModuleNotFoundError) as e:
215-
logger.debug(f"Failed to wrap {wrap_config}: {e}")
216-
217216
logger.debug("Successfully instrumented OpenAI API with Response extensions")
218217

219218
def _uninstrument(self, **kwargs):
220219
"""Remove instrumentation from OpenAI API."""
221220
super()._uninstrument(**kwargs)
222221

222+
for wrap_config in WRAPPED_METHODS:
223+
try:
224+
unwrap(wrap_config)
225+
logger.debug(f"Successfully unwrapped {wrap_config}")
226+
except Exception as e:
227+
logger.debug(f"Failed to unwrap {wrap_config}: {e}")
228+
223229
from opentelemetry.instrumentation.utils import unwrap as _unwrap
224230

225231
try:
@@ -231,11 +237,4 @@ def _uninstrument(self, **kwargs):
231237
except Exception as e:
232238
logger.debug(f"Failed to unwrap Responses API custom wrapper: {e}")
233239

234-
for wrap_config in WRAPPED_METHODS:
235-
try:
236-
unwrap(wrap_config)
237-
logger.debug(f"Successfully unwrapped {wrap_config}")
238-
except Exception as e:
239-
logger.debug(f"Failed to unwrap {wrap_config}: {e}")
240-
241240
logger.debug("Successfully removed OpenAI API instrumentation with Response extensions")

0 commit comments

Comments
 (0)