Skip to content

Commit eaacc97

Browse files
ericapisaniclaude
andauthored
refactor(ai): Remove gen_ai.tool.type span attribute (#5964)
- Remove setting of `gen_ai.tool.type` span data from all AI integrations (openai_agents, pydantic_ai, google_genai) - Remove the `SPANDATA.GEN_AI_TOOL_TYPE` constant - Clean up now-unused `MCPServer`/`HAS_MCP` imports in pydantic_ai integration Closes PY-2286 ## Test plan - [x] Linters pass (`tox -e linters`) - [x] mypy passes (`tox -e mypy`) - [ ] Integration tests pass for openai_agents, pydantic_ai, google_genai 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 301a879 commit eaacc97

File tree

9 files changed

+3
-55
lines changed

9 files changed

+3
-55
lines changed

sentry_sdk/consts.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,6 @@ class SPANDATA:
636636
Example: "rainy, 57°F"
637637
"""
638638

639-
GEN_AI_TOOL_TYPE = "gen_ai.tool.type"
640-
"""
641-
The type of tool being used.
642-
Example: "function"
643-
"""
644-
645639
GEN_AI_USAGE_INPUT_TOKENS = "gen_ai.usage.input_tokens"
646640
"""
647641
The number of tokens in the input.

sentry_sdk/integrations/google_genai/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ def _create_tool_span(tool_name: str, tool_doc: "Optional[str]") -> "Span":
597597
origin=ORIGIN,
598598
)
599599
span.set_data(SPANDATA.GEN_AI_TOOL_NAME, tool_name)
600-
span.set_data(SPANDATA.GEN_AI_TOOL_TYPE, "function")
601600
if tool_doc:
602601
span.set_data(SPANDATA.GEN_AI_TOOL_DESCRIPTION, tool_doc)
603602
return span

sentry_sdk/integrations/openai_agents/spans/execute_tool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ def execute_tool_span(
2323

2424
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "execute_tool")
2525

26-
if tool.__class__.__name__ == "FunctionTool":
27-
span.set_data(SPANDATA.GEN_AI_TOOL_TYPE, "function")
28-
2926
span.set_data(SPANDATA.GEN_AI_TOOL_NAME, tool.name)
3027
span.set_data(SPANDATA.GEN_AI_TOOL_DESCRIPTION, tool.description)
3128

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ def _create_mcp_execute_tool_spans(
247247
description=f"execute_tool {output.name}",
248248
start_timestamp=span.start_timestamp,
249249
) as execute_tool_span:
250-
execute_tool_span.set_data(SPANDATA.GEN_AI_TOOL_TYPE, "mcp")
251250
execute_tool_span.set_data(SPANDATA.GEN_AI_TOOL_NAME, output.name)
252251
if should_send_default_pii():
253252
execute_tool_span.set_data(

sentry_sdk/integrations/pydantic_ai/patches/tools.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
if TYPE_CHECKING:
1414
from typing import Any
1515

16-
try:
17-
from pydantic_ai.mcp import MCPServer # type: ignore
18-
19-
HAS_MCP = True
20-
except ImportError:
21-
HAS_MCP = False
22-
2316
try:
2417
from pydantic_ai._tool_manager import ToolManager # type: ignore
2518
from pydantic_ai.exceptions import ToolRetryError # type: ignore
@@ -52,11 +45,6 @@ async def wrapped_execute_tool_call(
5245
tool = self.tools.get(name) if self.tools else None
5346
selected_tool_definition = getattr(tool, "tool_def", None)
5447

55-
# Determine tool type by checking tool.toolset
56-
tool_type = "function"
57-
if tool and HAS_MCP and isinstance(tool.toolset, MCPServer):
58-
tool_type = "mcp"
59-
6048
# Get agent from contextvar
6149
agent = get_current_agent()
6250

@@ -73,7 +61,6 @@ async def wrapped_execute_tool_call(
7361
name,
7462
args_dict,
7563
agent,
76-
tool_type=tool_type,
7764
tool_definition=selected_tool_definition,
7865
) as span:
7966
try:
@@ -131,11 +118,6 @@ async def wrapped_call_tool(
131118
tool = self.tools.get(name) if self.tools else None
132119
selected_tool_definition = getattr(tool, "tool_def", None)
133120

134-
# Determine tool type by checking tool.toolset
135-
tool_type = "function" # default
136-
if tool and HAS_MCP and isinstance(tool.toolset, MCPServer):
137-
tool_type = "mcp"
138-
139121
# Get agent from contextvar
140122
agent = get_current_agent()
141123

@@ -152,7 +134,6 @@ async def wrapped_call_tool(
152134
name,
153135
args_dict,
154136
agent,
155-
tool_type=tool_type,
156137
tool_definition=selected_tool_definition,
157138
) as span:
158139
try:

sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def execute_tool_span(
1616
tool_name: str,
1717
tool_args: "Any",
1818
agent: "Any",
19-
tool_type: str = "function",
2019
tool_definition: "Optional[ToolDefinition]" = None,
2120
) -> "sentry_sdk.tracing.Span":
2221
"""Create a span for tool execution.
@@ -25,7 +24,6 @@ def execute_tool_span(
2524
tool_name: The name of the tool being executed
2625
tool_args: The arguments passed to the tool
2726
agent: The agent executing the tool
28-
tool_type: The type of tool ("function" for regular tools, "mcp" for MCP services)
2927
tool_definition: The definition of the tool, if available
3028
"""
3129
span = sentry_sdk.start_span(
@@ -35,7 +33,6 @@ def execute_tool_span(
3533
)
3634

3735
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "execute_tool")
38-
span.set_data(SPANDATA.GEN_AI_TOOL_TYPE, tool_type)
3936
span.set_data(SPANDATA.GEN_AI_TOOL_NAME, tool_name)
4037

4138
if tool_definition is not None and hasattr(tool_definition, "description"):

tests/integrations/google_genai/test_google_genai.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ def get_weather(location: str) -> str:
373373
assert tool_span["op"] == OP.GEN_AI_EXECUTE_TOOL
374374
assert tool_span["description"] == "execute_tool get_weather"
375375
assert tool_span["data"][SPANDATA.GEN_AI_TOOL_NAME] == "get_weather"
376-
assert tool_span["data"][SPANDATA.GEN_AI_TOOL_TYPE] == "function"
377376
assert (
378377
tool_span["data"][SPANDATA.GEN_AI_TOOL_DESCRIPTION]
379378
== "Get the weather for a location"

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,8 +1274,6 @@ def simple_test_tool(message: str) -> str:
12741274
assert tool_span["data"]["gen_ai.tool.input"] == '{"message": "hello"}'
12751275
assert tool_span["data"]["gen_ai.tool.name"] == "simple_test_tool"
12761276
assert tool_span["data"]["gen_ai.tool.output"] == "Tool executed with: hello"
1277-
assert tool_span["data"]["gen_ai.tool.type"] == "function"
1278-
12791277
assert ai_client_span2["description"] == "chat gpt-4"
12801278
assert ai_client_span2["data"]["gen_ai.agent.name"] == "test_agent"
12811279
assert ai_client_span2["data"]["gen_ai.operation.name"] == "chat"
@@ -1896,17 +1894,13 @@ async def test_mcp_tool_execution_spans(
18961894
# Find the MCP execute_tool span
18971895
mcp_tool_span = None
18981896
for span in spans:
1899-
if (
1900-
span.get("description") == "execute_tool test_mcp_tool"
1901-
and span.get("data", {}).get("gen_ai.tool.type") == "mcp"
1902-
):
1897+
if span.get("description") == "execute_tool test_mcp_tool":
19031898
mcp_tool_span = span
19041899
break
19051900

19061901
# Verify the MCP tool span was created
19071902
assert mcp_tool_span is not None, "MCP execute_tool span was not created"
19081903
assert mcp_tool_span["description"] == "execute_tool test_mcp_tool"
1909-
assert mcp_tool_span["data"]["gen_ai.tool.type"] == "mcp"
19101904
assert mcp_tool_span["data"]["gen_ai.tool.name"] == "test_mcp_tool"
19111905
assert mcp_tool_span["data"]["gen_ai.tool.input"] == '{"query": "search term"}'
19121906
assert (
@@ -2028,17 +2022,13 @@ async def test_mcp_tool_execution_with_error(
20282022
# Find the MCP execute_tool span with error
20292023
mcp_tool_span = None
20302024
for span in spans:
2031-
if (
2032-
span.get("description") == "execute_tool failing_mcp_tool"
2033-
and span.get("data", {}).get("gen_ai.tool.type") == "mcp"
2034-
):
2025+
if span.get("description") == "execute_tool failing_mcp_tool":
20352026
mcp_tool_span = span
20362027
break
20372028

20382029
# Verify the MCP tool span was created with error status
20392030
assert mcp_tool_span is not None, "MCP execute_tool span was not created"
20402031
assert mcp_tool_span["description"] == "execute_tool failing_mcp_tool"
2041-
assert mcp_tool_span["data"]["gen_ai.tool.type"] == "mcp"
20422032
assert mcp_tool_span["data"]["gen_ai.tool.name"] == "failing_mcp_tool"
20432033
assert mcp_tool_span["data"]["gen_ai.tool.input"] == '{"query": "test"}'
20442034
assert mcp_tool_span["data"]["gen_ai.tool.output"] is None
@@ -2158,17 +2148,13 @@ async def test_mcp_tool_execution_without_pii(
21582148
# Find the MCP execute_tool span
21592149
mcp_tool_span = None
21602150
for span in spans:
2161-
if (
2162-
span.get("description") == "execute_tool test_mcp_tool"
2163-
and span.get("data", {}).get("gen_ai.tool.type") == "mcp"
2164-
):
2151+
if span.get("description") == "execute_tool test_mcp_tool":
21652152
mcp_tool_span = span
21662153
break
21672154

21682155
# Verify the MCP tool span was created but without input/output
21692156
assert mcp_tool_span is not None, "MCP execute_tool span was not created"
21702157
assert mcp_tool_span["description"] == "execute_tool test_mcp_tool"
2171-
assert mcp_tool_span["data"]["gen_ai.tool.type"] == "mcp"
21722158
assert mcp_tool_span["data"]["gen_ai.tool.name"] == "test_mcp_tool"
21732159

21742160
# Verify input and output are not included when send_default_pii is False

tests/integrations/pydantic_ai/test_pydantic_ai.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ def add_numbers(a: int, b: int) -> int:
275275
tool_span = tool_spans[0]
276276
assert "execute_tool" in tool_span["description"]
277277
assert tool_span["data"]["gen_ai.operation.name"] == "execute_tool"
278-
assert tool_span["data"]["gen_ai.tool.type"] == "function"
279278
assert tool_span["data"]["gen_ai.tool.name"] == "add_numbers"
280279
assert "gen_ai.tool.input" in tool_span["data"]
281280
assert "gen_ai.tool.output" in tool_span["data"]
@@ -348,14 +347,12 @@ def add_numbers(a: int, b: int) -> float:
348347
model_retry_tool_span = tool_spans[0]
349348
assert "execute_tool" in model_retry_tool_span["description"]
350349
assert model_retry_tool_span["data"]["gen_ai.operation.name"] == "execute_tool"
351-
assert model_retry_tool_span["data"]["gen_ai.tool.type"] == "function"
352350
assert model_retry_tool_span["data"]["gen_ai.tool.name"] == "add_numbers"
353351
assert "gen_ai.tool.input" in model_retry_tool_span["data"]
354352

355353
tool_span = tool_spans[1]
356354
assert "execute_tool" in tool_span["description"]
357355
assert tool_span["data"]["gen_ai.operation.name"] == "execute_tool"
358-
assert tool_span["data"]["gen_ai.tool.type"] == "function"
359356
assert tool_span["data"]["gen_ai.tool.name"] == "add_numbers"
360357
assert "gen_ai.tool.input" in tool_span["data"]
361358
assert "gen_ai.tool.output" in tool_span["data"]
@@ -427,7 +424,6 @@ def add_numbers(a: Annotated[int, Field(gt=0, lt=0)], b: int) -> int:
427424
model_retry_tool_span = tool_spans[0]
428425
assert "execute_tool" in model_retry_tool_span["description"]
429426
assert model_retry_tool_span["data"]["gen_ai.operation.name"] == "execute_tool"
430-
assert model_retry_tool_span["data"]["gen_ai.tool.type"] == "function"
431427
assert model_retry_tool_span["data"]["gen_ai.tool.name"] == "add_numbers"
432428
assert "gen_ai.tool.input" in model_retry_tool_span["data"]
433429

0 commit comments

Comments
 (0)