From bd53f0e11ca4f8f13409b379cd293ba93317e3b5 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Mon, 5 Oct 2026 09:22:26 +0200 Subject: [PATCH] chore(pydantic-ai): Stop setting gen_ai.request.model on Invoke Agent spans --- .../integrations/pydantic_ai/spans/ai_client.py | 12 ++++++++++++ sentry_sdk/integrations/pydantic_ai/utils.py | 5 ----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py b/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py index bd9137c39c..4e7d8c88a8 100644 --- a/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py +++ b/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py @@ -290,6 +290,18 @@ def ai_client_context( ) _set_agent_data(context.span, agent) + + # Extract model information + model_obj = model + if not model_obj and agent and hasattr(agent, "model"): + model_obj = agent.model + + if model_obj: + # Set model name + model_name = _get_model_name(model_obj) + if model_name: + context.span.set_attribute(SPANDATA.GEN_AI_REQUEST_MODEL, model_name) + _set_model_data(context.span, agent, model, model_settings) _set_available_tools(context.span, agent) diff --git a/sentry_sdk/integrations/pydantic_ai/utils.py b/sentry_sdk/integrations/pydantic_ai/utils.py index ad9fd62c05..a6cc752a11 100644 --- a/sentry_sdk/integrations/pydantic_ai/utils.py +++ b/sentry_sdk/integrations/pydantic_ai/utils.py @@ -78,11 +78,6 @@ def _set_model_data( if hasattr(model_obj, "system"): span.set_attribute(SPANDATA.GEN_AI_PROVIDER_NAME, model_obj.system) - # Set model name - model_name = _get_model_name(model_obj) - if model_name: - span.set_attribute(SPANDATA.GEN_AI_REQUEST_MODEL, model_name) - # Extract model settings settings = model_settings if not settings and agent and hasattr(agent, "model_settings"):