Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions sentry_sdk/integrations/openai_agents/patches/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ def _get_model(
# because we only patch its direct methods, all underlying data can remain unchanged.
model = copy.copy(original_get_model(agent, run_config))

# Capture the request model name for spans (agent.model can be None when using defaults)
request_model_name = model.model if hasattr(model, "model") else str(model)
agent._sentry_request_model = request_model_name

# Wrap _fetch_response if it exists (for OpenAI models) to capture response model
if hasattr(model, "_fetch_response"):
original_fetch_response = model._fetch_response
Expand Down
3 changes: 0 additions & 3 deletions sentry_sdk/integrations/openai_agents/spans/ai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,9 @@ def ai_client_span(
agent: "Agent", get_response_kwargs: "dict[str, Any]"
) -> "Union[sentry_sdk.tracing.Span, StreamedSpan]":
# TODO-anton: implement other types of operations. Now "chat" is hardcoded.
# Get model name from agent.model or fall back to request model (for when agent.model is None/default)
model_name = None
if agent.model:
model_name = agent.model.model if hasattr(agent.model, "model") else agent.model
elif hasattr(agent, "_sentry_request_model"):
model_name = agent._sentry_request_model

client_options = sentry_sdk.get_client().options

Expand Down
3 changes: 0 additions & 3 deletions sentry_sdk/integrations/openai_agents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ def _set_agent_data(
if agent.model_settings.max_tokens:
set_on_span(SPANDATA.GEN_AI_REQUEST_MAX_TOKENS, agent.model_settings.max_tokens)

# Get model name from agent.model or fall back to request model (for when agent.model is None/default)
model_name = None
if agent.model:
model_name = agent.model.model if hasattr(agent.model, "model") else agent.model
elif hasattr(agent, "_sentry_request_model"):
model_name = agent._sentry_request_model

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Request model lost for default models

Medium Severity

Removing _sentry_request_model drops the resolved request model when agent.model is unset. Agents that use the SDK default or a RunConfig model no longer get gen_ai.request.model, and chat spans are named chat None.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5bb18fd. Configure here.


if model_name:
set_on_span(SPANDATA.GEN_AI_REQUEST_MODEL, model_name)
Expand Down
Loading