Skip to content

Commit b3e5d01

Browse files
simplify exception cases
1 parent ea91e54 commit b3e5d01

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

sentry_sdk/integrations/openai_agents/patches/agent_run.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ async def patched_run_single_turn(cls, *args, **kwargs):
9292
# Call original method with all the correct parameters
9393
try:
9494
result = await original_run_single_turn(*args, **kwargs)
95-
except AgentsException:
96-
# AgentsException is caught on AgentRunner.run().
97-
# Exceptions are captured and agent invocation spans are explicitly finished
98-
# as long as only AgentRunner.run() invokes AgentRunner._run_single_turn().
99-
raise
10095
except Exception as exc:
10196
_capture_exception(exc)
10297

sentry_sdk/integrations/openai_agents/patches/runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ async def wrapper(*args, **kwargs):
3838
args = (agent, *args[1:])
3939
try:
4040
run_result = await original_func(*args, **kwargs)
41+
except _SingleTurnException as exc:
42+
# Handled in _run_single_turn() patch.
43+
raise exc.original from None
4144
except AgentsException as exc:
4245
_capture_exception(exc)
4346

@@ -55,9 +58,6 @@ async def wrapper(*args, **kwargs):
5558
end_invoke_agent_span(context_wrapper, agent)
5659

5760
raise exc from None
58-
except _SingleTurnException as exc:
59-
# Handled in _run_single_turn() patch.
60-
raise exc.original from None
6161
except Exception as exc:
6262
# Invoke agent span is not finished in this case.
6363
# This is much less likely to occur than other cases because

0 commit comments

Comments
 (0)