fix(openai_agents): correctly patch turn_preparation.get_model to capture model spans - #7227
fix(openai_agents): correctly patch turn_preparation.get_model to capture model spans#7227x-tahosin wants to merge 2 commits into
Conversation
…urately Fixes missing hook in the openai_agents integration that prevents Sentry from capturing dynamic tool calls when using the openai Swarm/Agents SDK.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3508792. Configure here.
|
|
||
| agents.run_internal.run_loop.get_model = new_wrapped_get_model | ||
|
|
||
| if not use_run_hooks and hasattr(run_loop, "get_all_tools"): |
There was a problem hiding this comment.
Unreachable get_all_tools patch
High Severity
The new get_all_tools wrap is gated on not use_run_hooks, but this block only runs for openai-agents >= 0.8, where use_run_hooks is always true. The condition can never succeed, so the patch never installs and the PR's intended tool-call spans stay missing.
Reviewed by Cursor Bugbot for commit 3508792. Configure here.
3508792 to
ecb315d
Compare
|
Please open an issue describing the problem before opening a PR. |


Description
Fixes a typo in the
openai_agentsintegration where theget_modelfunction was incorrectly assigned to the wrong namespace.In
sentry_sdk/integrations/openai_agents/__init__.py, the documentation states that foropenai-agents >= 0.8.0,AgentRunner._get_model()was refactored toagents.run_internal.turn_preparation.get_model(). The integration correctly wrapsturn_preparation.get_model, but then incorrectly assigns the wrapped function back toagents.run_internal.run_loop.get_model.Because
run_loop.get_modelis not used by theopenai-agentsSDK internally to fetch the model, the wrapped method is never called, andgen_ai.model.invokespans may be missed or misattributed.This PR fixes the assignment target to
agents.run_internal.turn_preparation.get_model, ensuring the correct function is patched and the span is successfully tracked.Solution
Changed the assignment from
run_loop.get_modeltoturn_preparation.get_model.