Skip to content

Commit a2b4d81

Browse files
committed
explanation of defeat
1 parent 3885fb4 commit a2b4d81

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sentry_sdk/integrations/openai_agents/patches/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ async def async_wrapper(cls, *args, **kwargs):
4444
except Exception as exc:
4545
_capture_exception(exc)
4646

47-
# It could be that there is a "invoke agent" span still open (because its create in run_hooks)
47+
# It could be that there is a "invoke agent" span still open
48+
# (because its create in run_hooks without the context manager)
4849
current_span = sentry_sdk.get_current_span()
4950
if current_span.timestamp is None:
5051
current_span.__exit__(None, None, None)

sentry_sdk/integrations/openai_agents/patches/tools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ def create_wrapped_invoke(current_tool, current_on_invoke):
4848
async def sentry_wrapped_on_invoke_tool(*args, **kwargs):
4949
# type: (*Any, **Any) -> Any
5050
with execute_tool_span(current_tool, *args, **kwargs) as span:
51+
# We can not capture exceptions in tool execution here because
52+
# `_on_invoke_tool` is swallowing the exception here:
53+
# https://github.com/openai/openai-agents-python/blob/main/src/agents/tool.py#L409-L422
54+
# And because function_tool is a decorator with `default_tool_error_function` set as a default parameter
55+
# I was unable to monkey patch it because those are evaluated at module import time
56+
# and the SDK is too late to patch it. I was also unable to patch `_on_invoke_tool_impl`
57+
# because it is nested inside this import time code. As if they made it hard to patch on purpose...
5158
result = await current_on_invoke(*args, **kwargs)
5259
update_execute_tool_span(span, agent, current_tool, result)
5360

0 commit comments

Comments
 (0)