Skip to content

Commit 09df801

Browse files
dingsdaxclaude
andcommitted
fix(pydantic-ai): Restore tool description in execute_tool spans
The previous commit removed tool_definition from execute_tool_span, which inadvertently dropped gen_ai.tool.description from spans. Restore description support by extracting the description string from tool.tool_def in patches/tools.py and passing it as Optional[str] to execute_tool_span, avoiding the ToolDefinition type coupling while preserving the behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a8570fe commit 09df801

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

sentry_sdk/integrations/pydantic_ai/patches/tools.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ async def wrapped_execute_tool_call(
5656
if tool and HAS_MCP and isinstance(tool.toolset, MCPServer):
5757
tool_type = "mcp"
5858

59+
tool_def = getattr(tool, "tool_def", None)
60+
tool_description = getattr(tool_def, "description", None)
61+
5962
# Get agent from contextvar
6063
agent = get_current_agent()
6164

@@ -73,6 +76,7 @@ async def wrapped_execute_tool_call(
7376
args_dict,
7477
agent,
7578
tool_type=tool_type,
79+
tool_description=tool_description,
7680
) as span:
7781
try:
7882
result = await original_execute_tool_call(
@@ -133,6 +137,9 @@ async def wrapped_call_tool(
133137
if tool and HAS_MCP and isinstance(tool.toolset, MCPServer):
134138
tool_type = "mcp"
135139

140+
tool_def = getattr(tool, "tool_def", None)
141+
tool_description = getattr(tool_def, "description", None)
142+
136143
# Get agent from contextvar
137144
agent = get_current_agent()
138145

@@ -150,6 +157,7 @@ async def wrapped_call_tool(
150157
args_dict,
151158
agent,
152159
tool_type=tool_type,
160+
tool_description=tool_description,
153161
) as span:
154162
try:
155163
result = await original_call_tool(

sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313

1414
def execute_tool_span(
15-
tool_name: str, tool_args: "Any", agent: "Any", tool_type: str = "function"
15+
tool_name: str,
16+
tool_args: "Any",
17+
agent: "Any",
18+
tool_type: str = "function",
19+
tool_description: "Optional[str]" = None,
1620
) -> "sentry_sdk.tracing.Span":
1721
"""Create a span for tool execution.
1822
@@ -21,6 +25,7 @@ def execute_tool_span(
2125
tool_args: The arguments passed to the tool
2226
agent: The agent executing the tool
2327
tool_type: The type of tool ("function" for regular tools, "mcp" for MCP services)
28+
tool_description: Optional description of the tool
2429
"""
2530
span = sentry_sdk.start_span(
2631
op=OP.GEN_AI_EXECUTE_TOOL,
@@ -32,6 +37,9 @@ def execute_tool_span(
3237
span.set_data(SPANDATA.GEN_AI_TOOL_TYPE, tool_type)
3338
span.set_data(SPANDATA.GEN_AI_TOOL_NAME, tool_name)
3439

40+
if tool_description is not None:
41+
span.set_data(SPANDATA.GEN_AI_TOOL_DESCRIPTION, tool_description)
42+
3543
_set_agent_data(span, agent)
3644

3745
if _should_send_prompts() and tool_args is not None:

0 commit comments

Comments
 (0)