Skip to content

fix(openai_agents): correctly patch turn_preparation.get_model to capture model spans - #7227

Open
x-tahosin wants to merge 2 commits into
getsentry:masterfrom
x-tahosin:codex/bugsmash-streamed-tool-spans
Open

fix(openai_agents): correctly patch turn_preparation.get_model to capture model spans#7227
x-tahosin wants to merge 2 commits into
getsentry:masterfrom
x-tahosin:codex/bugsmash-streamed-tool-spans

Conversation

@x-tahosin

@x-tahosin x-tahosin commented Aug 23, 2026

Copy link
Copy Markdown

Description

Fixes a typo in the openai_agents integration where the get_model function was incorrectly assigned to the wrong namespace.

In sentry_sdk/integrations/openai_agents/__init__.py, the documentation states that for openai-agents >= 0.8.0, AgentRunner._get_model() was refactored to agents.run_internal.turn_preparation.get_model(). The integration correctly wraps turn_preparation.get_model, but then incorrectly assigns the wrapped function back to agents.run_internal.run_loop.get_model.

Because run_loop.get_model is not used by the openai-agents SDK internally to fetch the model, the wrapped method is never called, and gen_ai.model.invoke spans 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_model to turn_preparation.get_model.

…urately

Fixes missing hook in the openai_agents integration that prevents Sentry from capturing dynamic tool calls when using the openai Swarm/Agents SDK.
@x-tahosin
x-tahosin requested a review from a team as a code owner August 23, 2026 16:24
Comment thread sentry_sdk/integrations/openai_agents/__init__.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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"):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3508792. Configure here.

@x-tahosin
x-tahosin force-pushed the codex/bugsmash-streamed-tool-spans branch from 3508792 to ecb315d Compare August 23, 2026 17:17
@x-tahosin x-tahosin changed the title fix(openai_agents): patch get_all_tools to capture function calls accurately fix(openai_agents): correctly patch turn_preparation.get_model to capture model spans Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant