-
Notifications
You must be signed in to change notification settings - Fork 608
Expand file tree
/
Copy path__init__.py
More file actions
48 lines (38 loc) · 1.39 KB
/
__init__.py
File metadata and controls
48 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from sentry_sdk.integrations import DidNotEnable, Integration
try:
import pydantic_ai # type: ignore # noqa: F401
except ImportError:
raise DidNotEnable("pydantic-ai not installed")
from .patches import (
_patch_agent_run,
_patch_graph_nodes,
_patch_tool_execution,
)
class PydanticAIIntegration(Integration):
identifier = "pydantic_ai"
origin = f"auto.ai.{identifier}"
def __init__(
self, include_prompts: bool = True, handled_tool_call_exceptions: bool = True
) -> None:
"""
Initialize the Pydantic AI integration.
Args:
include_prompts: Whether to include prompts and messages in span data.
Requires send_default_pii=True. Defaults to True.
handled_tool_exceptions: Capture tool call exceptions that Pydantic AI
internally prevents from bubbling up.
"""
self.include_prompts = include_prompts
self.handled_tool_call_exceptions = handled_tool_call_exceptions
@staticmethod
def setup_once() -> None:
"""
Set up the pydantic-ai integration.
This patches the key methods in pydantic-ai to create Sentry spans for:
- Agent invocations (Agent.run methods)
- Model requests (AI client calls)
- Tool executions
"""
_patch_agent_run()
_patch_graph_nodes()
_patch_tool_execution()