From 6ef56fdc2b3b757974b5d23c89a9f30f86c1c3b0 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 8 Apr 2026 10:37:16 +0200 Subject: [PATCH] ref(pydantic-ai): Remove dead Model.request patch --- .../integrations/pydantic_ai/__init__.py | 2 - .../pydantic_ai/patches/__init__.py | 1 - .../pydantic_ai/patches/model_request.py | 40 ------------------- 3 files changed, 43 deletions(-) delete mode 100644 sentry_sdk/integrations/pydantic_ai/patches/model_request.py diff --git a/sentry_sdk/integrations/pydantic_ai/__init__.py b/sentry_sdk/integrations/pydantic_ai/__init__.py index 0f0de53fa5..eb40732d7a 100644 --- a/sentry_sdk/integrations/pydantic_ai/__init__.py +++ b/sentry_sdk/integrations/pydantic_ai/__init__.py @@ -10,7 +10,6 @@ from .patches import ( _patch_agent_run, _patch_graph_nodes, - _patch_model_request, _patch_tool_execution, ) @@ -46,5 +45,4 @@ def setup_once() -> None: """ _patch_agent_run() _patch_graph_nodes() - _patch_model_request() _patch_tool_execution() diff --git a/sentry_sdk/integrations/pydantic_ai/patches/__init__.py b/sentry_sdk/integrations/pydantic_ai/patches/__init__.py index de28780728..d0ea6242b4 100644 --- a/sentry_sdk/integrations/pydantic_ai/patches/__init__.py +++ b/sentry_sdk/integrations/pydantic_ai/patches/__init__.py @@ -1,4 +1,3 @@ from .agent_run import _patch_agent_run # noqa: F401 from .graph_nodes import _patch_graph_nodes # noqa: F401 -from .model_request import _patch_model_request # noqa: F401 from .tools import _patch_tool_execution # noqa: F401 diff --git a/sentry_sdk/integrations/pydantic_ai/patches/model_request.py b/sentry_sdk/integrations/pydantic_ai/patches/model_request.py deleted file mode 100644 index 94a96161f3..0000000000 --- a/sentry_sdk/integrations/pydantic_ai/patches/model_request.py +++ /dev/null @@ -1,40 +0,0 @@ -from functools import wraps -from typing import TYPE_CHECKING - -from sentry_sdk.integrations import DidNotEnable - -try: - from pydantic_ai import models # type: ignore -except ImportError: - raise DidNotEnable("pydantic-ai not installed") - -from ..spans import ai_client_span, update_ai_client_span - - -if TYPE_CHECKING: - from typing import Any - - -def _patch_model_request() -> None: - """ - Patches model request execution to create AI client spans. - - In pydantic-ai, model requests are handled through the Model interface. - We need to patch the request method on models to create spans. - """ - - # Patch the base Model class's request method - if hasattr(models, "Model"): - original_request = models.Model.request - - @wraps(original_request) - async def wrapped_request( - self: "Any", messages: "Any", *args: "Any", **kwargs: "Any" - ) -> "Any": - # Pass all messages (full conversation history) - with ai_client_span(messages, None, self, None) as span: - result = await original_request(self, messages, *args, **kwargs) - update_ai_client_span(span, result) - return result - - models.Model.request = wrapped_request