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 @@ -719,7 +719,7 @@ async def async_wrapped(*args: "Any", **kwargs: "Any") -> "Any":
# Capture tool output
with capture_internal_exceptions():
span.set_attribute(
SPANDATA.GEN_AI_TOOL_OUTPUT, safe_serialize(result)
SPANDATA.GEN_AI_TOOL_CALL_RESULT, safe_serialize(result)
)

return result
Expand All @@ -746,7 +746,7 @@ def sync_wrapped(*args: "Any", **kwargs: "Any") -> "Any":
# Capture tool output
with capture_internal_exceptions():
span.set_attribute(
SPANDATA.GEN_AI_TOOL_OUTPUT, safe_serialize(result)
SPANDATA.GEN_AI_TOOL_CALL_RESULT, safe_serialize(result)
)

return result
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 @@ -755,7 +755,7 @@ def on_tool_end(
)

if sentry_sdk.get_client().options["data_collection"]["gen_ai"]["outputs"]:
set_data_normalized(span, SPANDATA.GEN_AI_TOOL_OUTPUT, output)
set_data_normalized(span, SPANDATA.GEN_AI_TOOL_CALL_RESULT, output)

self._exit_span(span, run_id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update_execute_tool_span(
span.status = SpanStatus.ERROR

if client.options["data_collection"]["gen_ai"]["outputs"]:
span.set_attribute(SPANDATA.GEN_AI_TOOL_OUTPUT, result)
span.set_attribute(SPANDATA.GEN_AI_TOOL_CALL_RESULT, result)

# Add conversation ID from agent
conv_id = getattr(agent, "_sentry_conversation_id", None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def update_execute_tool_span(span: "Span", result: "Any") -> None:
):
return

span.set_attribute(SPANDATA.GEN_AI_TOOL_OUTPUT, safe_serialize(result))
span.set_attribute(SPANDATA.GEN_AI_TOOL_CALL_RESULT, safe_serialize(result))
14 changes: 7 additions & 7 deletions tests/integrations/langchain/test_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ def test_tool_execution_span_no_sensitive_data(
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_TOOL_CALL_RESULT not in tool_exec_span.get("attributes", {})

assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get(
"attributes", {}
Expand Down Expand Up @@ -1267,7 +1267,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_CALL_ARGUMENTS]
assert 5 == int(tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_OUTPUT])
assert 5 == int(tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_RESULT])

assert json.loads(
chat_spans[0]["attributes"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
Expand Down Expand Up @@ -1439,7 +1439,7 @@ def test_langchain_openai_tools_agent_no_sensitive_data(
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_TOOL_CALL_RESULT not in tool_exec_span.get("attributes", {})

assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get(
"attributes", {}
Expand Down Expand Up @@ -1666,7 +1666,7 @@ def test_langchain_openai_tools_agent_stream_no_sensitive_data(
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_TOOL_CALL_RESULT not in tool_exec_span.get("attributes", {})

assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans[0].get(
"attributes", {}
Expand Down Expand Up @@ -1854,7 +1854,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_CALL_ARGUMENTS]
assert 5 == int(tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_OUTPUT])
assert 5 == int(tool_exec_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_RESULT])

assert json.loads(
chat_spans[0]["attributes"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
Expand Down Expand Up @@ -3365,12 +3365,12 @@ def test_langchain_data_collection_request_tool_call_params(
pytest.param(
{"gen_ai": {"inputs": True, "outputs": False}},
{SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS: {"word": "eudca"}},
[SPANDATA.GEN_AI_TOOL_OUTPUT],
[SPANDATA.GEN_AI_TOOL_CALL_RESULT],
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_CALL_RESULT: 5},
[SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS],
id="gen-ai-outputs-enabled-inputs-disabled",
),
Expand Down
15 changes: 11 additions & 4 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,10 @@ async def test_tool_execution_span(
== '{"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 (
tool_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_RESULT]
== "Tool executed with: hello"
)
assert ai_client_span2["name"] == "chat gpt-4"
assert ai_client_span2["attributes"]["gen_ai.agent.name"] == "test_agent"
assert ai_client_span2["attributes"]["gen_ai.operation.name"] == "chat"
Expand Down Expand Up @@ -1544,7 +1547,10 @@ async def test_run_streamed_tool_execution_span(
== '{"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 (
tool_span["attributes"][SPANDATA.GEN_AI_TOOL_CALL_RESULT]
== "Tool executed with: hello"
)


@pytest.fixture
Expand Down Expand Up @@ -1698,10 +1704,11 @@ async def test_tool_execution_span_data_collection(

if expect_output:
assert (
tool_span_data[SPANDATA.GEN_AI_TOOL_OUTPUT] == "Tool executed with: hello"
tool_span_data[SPANDATA.GEN_AI_TOOL_CALL_RESULT]
== "Tool executed with: hello"
)
else:
assert SPANDATA.GEN_AI_TOOL_OUTPUT not in tool_span_data
assert SPANDATA.GEN_AI_TOOL_CALL_RESULT not in tool_span_data


@pytest.mark.asyncio
Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/pydantic_ai/test_pydantic_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def add_numbers(a: int, b: int) -> int:
assert tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
assert tool_span["attributes"]["gen_ai.tool.name"] == "add_numbers"
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS in tool_span["attributes"]
assert "gen_ai.tool.output" in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_RESULT in tool_span["attributes"]

# Check chat spans have available_tools
for chat_span in chat_spans:
Expand Down Expand Up @@ -512,7 +512,7 @@ def add_numbers(a: int, b: int) -> float:
assert tool_span["attributes"]["gen_ai.operation.name"] == "execute_tool"
assert tool_span["attributes"]["gen_ai.tool.name"] == "add_numbers"
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS in tool_span["attributes"]
assert "gen_ai.tool.output" in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_RESULT in tool_span["attributes"]

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


@pytest.mark.asyncio
Expand Down Expand Up @@ -874,7 +874,7 @@ def sensitive_tool(data: str) -> str:
# If tool was executed, verify input/output are not captured
for tool_span in tool_spans:
assert SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS not in tool_span["attributes"]
assert "gen_ai.tool.output" not in tool_span["attributes"]
assert SPANDATA.GEN_AI_TOOL_CALL_RESULT not in tool_span["attributes"]


@pytest.mark.asyncio
Expand Down Expand Up @@ -3079,7 +3079,7 @@ def add_numbers(a: int, b: int) -> int:
# Derive the expected return value from the arguments the model actually
# 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
assert SPANDATA.GEN_AI_TOOL_CALL_RESULT not in tool_span
tool_input = json.loads(tool_span[SPANDATA.GEN_AI_TOOL_CALL_ARGUMENTS])
expected_tool_return = str(tool_input["a"] + tool_input["b"])

Expand Down
Loading