Skip to content

Commit 90f5dba

Browse files
capture_exception first
1 parent cea38a2 commit 90f5dba

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

sentry_sdk/integrations/openai_agents/patches/agent_run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ async def patched_run_single_turn(cls, *args, **kwargs):
9191
try:
9292
result = await original_run_single_turn(*args, **kwargs)
9393
except Exception as exc:
94+
_capture_exception(exc)
95+
9496
if span is not None and span.timestamp is None:
9597
_record_exception_on_span(span, exc)
9698
end_invoke_agent_span(context_wrapper, agent)
9799

98-
_capture_exception(exc)
99100
raise exc from None
100101

101102
return result

sentry_sdk/integrations/openai_agents/patches/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ async def wrapper(*args, **kwargs):
3737
try:
3838
run_result = await original_func(*args, **kwargs)
3939
except AgentsException as exc:
40+
_capture_exception(exc)
41+
4042
context_wrapper = getattr(exc.run_data, "context_wrapper", None)
4143
if context_wrapper is not None:
4244
invoke_agent_span = getattr(
@@ -50,7 +52,6 @@ async def wrapper(*args, **kwargs):
5052
_record_exception_on_span(invoke_agent_span, exc)
5153
end_invoke_agent_span(context_wrapper, agent)
5254

53-
_capture_exception(exc)
5455
raise exc from None
5556

5657
end_invoke_agent_span(run_result.context_wrapper, agent)

0 commit comments

Comments
 (0)