-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix:Use JSON string instead of dic for span attributes when content capture is disabled #4101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
78e6962
c743d2d
19f3b63
7096757
40a9daf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -473,24 +473,31 @@ async def test_call_llm_disabling_request_response_content( | |
| # Act | ||
| trace_call_llm(invocation_context, 'test_event_id', llm_request, llm_response) | ||
|
|
||
| # Assert | ||
| assert not any( | ||
| arg_name == 'gcp.vertex.agent.llm_request' and arg_value != {} | ||
| for arg_name, arg_value in ( | ||
| call_obj.args | ||
| for call_obj in mock_span_fixture.set_attribute.call_args_list | ||
| ) | ||
| ), "Attribute 'gcp.vertex.agent.llm_request' was incorrectly set on the span." | ||
|
|
||
| assert not any( | ||
| arg_name == 'gcp.vertex.agent.llm_response' and arg_value != {} | ||
| for arg_name, arg_value in ( | ||
| call_obj.args | ||
| for call_obj in mock_span_fixture.set_attribute.call_args_list | ||
| ) | ||
| ), ( | ||
| "Attribute 'gcp.vertex.agent.llm_response' was incorrectly set on the" | ||
| ' span.' | ||
| # Assert - Check attributes are set to JSON string '{}' not dict {} | ||
| llm_request_calls = [ | ||
| call | ||
| for call in mock_span_fixture.set_attribute.call_args_list | ||
| if call.args[0] == 'gcp.vertex.agent.llm_request' | ||
| ] | ||
| assert ( | ||
| len(llm_request_calls) == 1 | ||
| ), "Expected 'gcp.vertex.agent.llm_request' to be set exactly once" | ||
| assert llm_request_calls[0].args[1] == '{}', ( | ||
| "Expected JSON string '{}' for llm_request when content capture is" | ||
| f' disabled, got {llm_request_calls[0].args[1]!r}' | ||
| ) | ||
|
|
||
| llm_response_calls = [ | ||
| call | ||
| for call in mock_span_fixture.set_attribute.call_args_list | ||
| if call.args[0] == 'gcp.vertex.agent.llm_response' | ||
| ] | ||
| assert ( | ||
| len(llm_response_calls) == 1 | ||
| ), "Expected 'gcp.vertex.agent.llm_response' to be set exactly once" | ||
| assert llm_response_calls[0].args[1] == '{}', ( | ||
| "Expected JSON string '{}' for llm_response when content capture is" | ||
| f' disabled, got {llm_response_calls[0].args[1]!r}' | ||
| ) | ||
|
||
|
|
||
|
|
||
|
|
@@ -536,27 +543,31 @@ def test_trace_tool_call_disabling_request_response_content( | |
| function_response_event=mock_event_fixture, | ||
| ) | ||
|
|
||
| # Assert | ||
| assert not any( | ||
| arg_name == 'gcp.vertex.agent.tool_call_args' and arg_value != {} | ||
| for arg_name, arg_value in ( | ||
| call_obj.args | ||
| for call_obj in mock_span_fixture.set_attribute.call_args_list | ||
| ) | ||
| ), ( | ||
| "Attribute 'gcp.vertex.agent.tool_call_args' was incorrectly set on the" | ||
| ' span.' | ||
| # Assert - Check attributes are set to JSON string '{}' not dict {} | ||
| tool_args_calls = [ | ||
| call | ||
| for call in mock_span_fixture.set_attribute.call_args_list | ||
| if call.args[0] == 'gcp.vertex.agent.tool_call_args' | ||
| ] | ||
| assert ( | ||
| len(tool_args_calls) == 1 | ||
| ), "Expected 'gcp.vertex.agent.tool_call_args' to be set exactly once" | ||
| assert tool_args_calls[0].args[1] == '{}', ( | ||
| "Expected JSON string '{}' for tool_call_args when content capture is" | ||
| f' disabled, got {tool_args_calls[0].args[1]!r}' | ||
| ) | ||
|
|
||
| assert not any( | ||
| arg_name == 'gcp.vertex.agent.tool_response' and arg_value != {} | ||
| for arg_name, arg_value in ( | ||
| call_obj.args | ||
| for call_obj in mock_span_fixture.set_attribute.call_args_list | ||
| ) | ||
| ), ( | ||
| "Attribute 'gcp.vertex.agent.tool_response' was incorrectly set on the" | ||
| ' span.' | ||
| tool_response_calls = [ | ||
| call | ||
| for call in mock_span_fixture.set_attribute.call_args_list | ||
| if call.args[0] == 'gcp.vertex.agent.tool_response' | ||
| ] | ||
| assert ( | ||
| len(tool_response_calls) == 1 | ||
| ), "Expected 'gcp.vertex.agent.tool_response' to be set exactly once" | ||
| assert tool_response_calls[0].args[1] == '{}', ( | ||
| "Expected JSON string '{}' for tool_response when content capture is" | ||
| f' disabled, got {tool_response_calls[0].args[1]!r}' | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -584,14 +595,16 @@ def test_trace_merged_tool_disabling_request_response_content( | |
| function_response_event=mock_event_fixture, | ||
| ) | ||
|
|
||
| # Assert | ||
| assert not any( | ||
| arg_name == 'gcp.vertex.agent.tool_response' and arg_value != {} | ||
| for arg_name, arg_value in ( | ||
| call_obj.args | ||
| for call_obj in mock_span_fixture.set_attribute.call_args_list | ||
| ) | ||
| ), ( | ||
| "Attribute 'gcp.vertex.agent.tool_response' was incorrectly set on the" | ||
| ' span.' | ||
| # Assert - Check attribute is set to JSON string '{}' not dict {} | ||
| tool_response_calls = [ | ||
| call | ||
| for call in mock_span_fixture.set_attribute.call_args_list | ||
| if call.args[0] == 'gcp.vertex.agent.tool_response' | ||
| ] | ||
| assert ( | ||
| len(tool_response_calls) == 1 | ||
| ), "Expected 'gcp.vertex.agent.tool_response' to be set exactly once" | ||
| assert tool_response_calls[0].args[1] == '{}', ( | ||
| "Expected JSON string '{}' for tool_response when content capture is" | ||
| f' disabled, got {tool_response_calls[0].args[1]!r}' | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve maintainability and avoid using a magic string, consider defining a constant for
'{}'at the module level and reusing it here and in other similar places.For example:
This change would apply to all 6 locations modified in this PR (lines 152, 182, 222, 268, 293, 349) and could also replace other existing instances of the
'{}'literal in this file for consistency.