Skip to content
Merged
Changes from 5 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
21 changes: 19 additions & 2 deletions sentry_sdk/integrations/pydantic_ai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools

from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.utils import capture_internal_exceptions
from sentry_sdk.utils import capture_internal_exceptions, parse_version

try:
import pydantic_ai # type: ignore # noqa: F401
Expand All @@ -10,6 +10,7 @@
raise DidNotEnable("pydantic-ai not installed")


Comment thread
sentry-warden[bot] marked this conversation as resolved.
from importlib.metadata import PackageNotFoundError, version
Comment thread
alexander-alderman-webb marked this conversation as resolved.
from typing import TYPE_CHECKING

from .patches import (
Expand Down Expand Up @@ -164,9 +165,25 @@ def setup_once() -> None:
Hooks = None
PydanticAIIntegration.are_request_hooks_available = False

if Hooks is None:
try:
PYDANTIC_AI_VERSION = version("pydantic-ai-slim")
except PackageNotFoundError:
return
Comment thread
alexander-alderman-webb marked this conversation as resolved.

Comment thread
alexander-alderman-webb marked this conversation as resolved.
PYDANTIC_AI_VERSION = parse_version(PYDANTIC_AI_VERSION)
if PYDANTIC_AI_VERSION is None:
return

# ModelRequestContext.model added in https://github.com/pydantic/pydantic-ai/commit/f1260dfe09907f17688eee1646daf898fc428d4c
if PYDANTIC_AI_VERSION < (
1,
73,
):
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Comment thread
cursor[bot] marked this conversation as resolved.
_patch_graph_nodes()
return

if Hooks is None:
return
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Outdated

hooks = Hooks()
register_hooks(hooks)
Loading