Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/google_genai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ async def async_wrapped(*args: "Any", **kwargs: "Any") -> "Any":
tool_input = _capture_tool_input(args, kwargs, tool)
with capture_internal_exceptions():
span.set_attribute(
SPANDATA.GEN_AI_TOOL_INPUT, safe_serialize(tool_input)
SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS, safe_serialize(tool_input)
)

try:
Expand All @@ -737,7 +737,7 @@ def sync_wrapped(*args: "Any", **kwargs: "Any") -> "Any":
tool_input = _capture_tool_input(args, kwargs, tool)
with capture_internal_exceptions():
span.set_attribute(
SPANDATA.GEN_AI_TOOL_INPUT, safe_serialize(tool_input)
SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS, safe_serialize(tool_input)
)

try:
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def on_tool_start(

set_data_normalized(
span,
SPANDATA.GEN_AI_TOOL_INPUT,
SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS,
kwargs.get("inputs", [input_str]),
)

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/openai_agents/patches/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def on_tool_start(
if not client.options["data_collection"]["gen_ai"]["inputs"]:
return

span.set_attribute(SPANDATA.GEN_AI_TOOL_INPUT, context.tool_arguments)
span.set_attribute(SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS, context.tool_arguments)

async def on_tool_end(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def execute_tool_span(
):
return span

span.set_attribute(SPANDATA.GEN_AI_TOOL_INPUT, safe_serialize(tool_args))
span.set_attribute(SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS, safe_serialize(tool_args))

return span

Expand Down
22 changes: 14 additions & 8 deletions tests/integrations/langchain/test_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def test_tool_execution_span(
chat_spans[1]["attributes"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "gpt-4-0613"
)

assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_INPUT]
assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS]

assert "5" in chat_spans[1]["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT]

Expand Down Expand Up @@ -1088,7 +1088,9 @@ def test_tool_execution_span_no_sensitive_data(
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in chat_spans[0].get("attributes", {})
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in chat_spans[1].get("attributes", {})
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in chat_spans[1].get("attributes", {})
assert SPANDATA.GEN_AI_TOOL_INPUT not in tool_exec_span.get("attributes", {})
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS not in tool_exec_span.get(
"attributes", {}
)
assert SPANDATA.GEN_AI_TOOL_OUTPUT not in tool_exec_span.get("attributes", {})

assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get(
Expand Down Expand Up @@ -1264,7 +1266,7 @@ def test_langchain_openai_tools_agent(
)

assert "5" in chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT]
assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_INPUT]
assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS]
assert 5 == int(tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_OUTPUT])

assert json.loads(
Expand Down Expand Up @@ -1434,7 +1436,9 @@ def test_langchain_openai_tools_agent_no_sensitive_data(
)
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in chat_spans[1].get("attributes", {})
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in chat_spans[1].get("attributes", {})
assert SPANDATA.GEN_AI_TOOL_INPUT not in tool_exec_span.get("attributes", {})
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS not in tool_exec_span.get(
"attributes", {}
)
assert SPANDATA.GEN_AI_TOOL_OUTPUT not in tool_exec_span.get("attributes", {})

assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get(
Expand Down Expand Up @@ -1659,7 +1663,9 @@ def test_langchain_openai_tools_agent_stream_no_sensitive_data(
)
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in chat_spans[1].get("attributes", {})
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in chat_spans[1].get("attributes", {})
assert SPANDATA.GEN_AI_TOOL_INPUT not in tool_exec_span.get("attributes", {})
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS not in tool_exec_span.get(
"attributes", {}
)
assert SPANDATA.GEN_AI_TOOL_OUTPUT not in tool_exec_span.get("attributes", {})

assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get(
Expand Down Expand Up @@ -1847,7 +1853,7 @@ def test_langchain_openai_tools_agent_stream(
)

assert "5" in chat_spans[0]["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT]
assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_INPUT]
assert "word" in tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS]
assert 5 == int(tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_OUTPUT])

assert json.loads(
Expand Down Expand Up @@ -3358,14 +3364,14 @@ def test_langchain_data_collection_request_tool_call_params(
[
pytest.param(
{"gen_ai": {"inputs": True, "outputs": False}},
{SPANDATA.GEN_AI_TOOL_INPUT: {"word": "eudca"}},
{SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS: {"word": "eudca"}},
[SPANDATA.GEN_AI_TOOL_OUTPUT],
id="gen-ai-inputs-enabled-outputs-disabled",
),
pytest.param(
{"gen_ai": {"inputs": False, "outputs": True}},
{SPANDATA.GEN_AI_TOOL_OUTPUT: 5},
[SPANDATA.GEN_AI_TOOL_INPUT],
[SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS],
id="gen-ai-outputs-enabled-inputs-disabled",
),
],
Expand Down
17 changes: 13 additions & 4 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,10 @@ async def test_tool_execution_span(
assert tool_span["attributes"]["gen_ai.request.top_p"] == 1.0
assert tool_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
assert tool_span["attributes"]["gen_ai.tool.description"] == "A simple tool"
assert tool_span["attributes"]["gen_ai.tool.input"] == '{"message": "hello"}'
assert (
tool_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS]
== '{"message": "hello"}'
)
assert tool_span["attributes"]["gen_ai.tool.name"] == "simple_test_tool"
assert tool_span["attributes"]["gen_ai.tool.output"] == "Tool executed with: hello"
assert ai_client_span2["name"] == "chat gpt-4"
Expand Down Expand Up @@ -1578,7 +1581,10 @@ async def test_run_streamed_tool_execution_span(
assert tool_span["attributes"]["gen_ai.request.top_p"] == 1.0
assert tool_span["attributes"][SPANDATA.GEN_AI_PROVIDER_NAME] == "openai"
assert tool_span["attributes"]["gen_ai.tool.description"] == "A simple tool"
assert tool_span["attributes"]["gen_ai.tool.input"] == '{"message": "hello"}'
assert (
tool_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS]
== '{"message": "hello"}'
)
assert tool_span["attributes"]["gen_ai.tool.name"] == "simple_test_tool"
assert tool_span["attributes"]["gen_ai.tool.output"] == "Tool executed with: hello"

Expand Down Expand Up @@ -1725,9 +1731,12 @@ async def test_tool_execution_span_data_collection(
)

if expect_input:
assert tool_span_data[SPANDATA.GEN_AI_TOOL_INPUT] == '{"message": "hello"}'
assert (
tool_span_data[SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS]
== '{"message": "hello"}'
)
else:
assert SPANDATA.GEN_AI_TOOL_INPUT not in tool_span_data
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS not in tool_span_data

if expect_output:
assert (
Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/pydantic_ai/test_pydantic_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def add_numbers(a: int, b: int) -> int:
assert "execute_tool" in tool_span["name"]
assert tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
assert tool_span["attributes"]["gen_ai.tool.name"] == "add_numbers"
assert "gen_ai.tool.input" in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS in tool_span["attributes"]
assert "gen_ai.tool.output" in tool_span["attributes"]

# Check chat spans have available_tools
Expand Down Expand Up @@ -505,13 +505,13 @@ def add_numbers(a: int, b: int) -> float:
model_retry_tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
)
assert model_retry_tool_span["attributes"]["gen_ai.tool.name"] == "add_numbers"
assert "gen_ai.tool.input" in model_retry_tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS in model_retry_tool_span["attributes"]

tool_span = tool_spans[1]
assert "execute_tool" in tool_span["name"]
assert tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
assert tool_span["attributes"]["gen_ai.tool.name"] == "add_numbers"
assert "gen_ai.tool.input" in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS in tool_span["attributes"]
assert "gen_ai.tool.output" in tool_span["attributes"]

# Check chat spans have available_tools
Expand Down Expand Up @@ -636,7 +636,7 @@ def multiply(a: int, b: int) -> int:
# Check tool span
tool_span = tool_spans[0]
assert tool_span["attributes"]["gen_ai.tool.name"] == "multiply"
assert "gen_ai.tool.input" in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS in tool_span["attributes"]
assert "gen_ai.tool.output" in tool_span["attributes"]


Expand Down Expand Up @@ -873,7 +873,7 @@ def sensitive_tool(data: str) -> str:

# If tool was executed, verify input/output are not captured
for tool_span in tool_spans:
assert "gen_ai.tool.input" not in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS not in tool_span["attributes"]
assert "gen_ai.tool.output" not in tool_span["attributes"]


Expand Down Expand Up @@ -3080,7 +3080,7 @@ def add_numbers(a: int, b: int) -> int:
# sent, so the assertion does not depend on the test model's defaults.
tool_span = tool_spans[0]
assert SPANDATA.GEN_AI_TOOL_OUTPUT not in tool_span
tool_input = json.loads(tool_span[SPANDATA.GEN_AI_TOOL_INPUT])
tool_input = json.loads(tool_span[SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS])
expected_tool_return = str(tool_input["a"] + tool_input["b"])

tool_messages = [
Expand Down
Loading