@@ -221,6 +221,19 @@ def test_langchain_agent(
221
221
in chat_spans [1 ]["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
222
222
)
223
223
assert "5" in chat_spans [1 ]["data" ][SPANDATA .GEN_AI_RESPONSE_TEXT ]
224
+
225
+ # Verify tool calls are recorded when PII is enabled
226
+ assert SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS in chat_spans [0 ].get (
227
+ "data" , {}
228
+ ), "Tool calls should be recorded when send_default_pii=True and include_prompts=True"
229
+ tool_calls_data = chat_spans [0 ]["data" ][SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS ]
230
+ assert isinstance (tool_calls_data , (list , str )) # Could be serialized
231
+ if isinstance (tool_calls_data , str ):
232
+ assert "get_word_length" in tool_calls_data
233
+ elif isinstance (tool_calls_data , list ) and len (tool_calls_data ) > 0 :
234
+ # Check if tool calls contain expected function name
235
+ tool_call_str = str (tool_calls_data )
236
+ assert "get_word_length" in tool_call_str
224
237
else :
225
238
assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in chat_spans [0 ].get ("data" , {})
226
239
assert SPANDATA .GEN_AI_RESPONSE_TEXT not in chat_spans [0 ].get ("data" , {})
@@ -229,6 +242,29 @@ def test_langchain_agent(
229
242
assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in tool_exec_span .get ("data" , {})
230
243
assert SPANDATA .GEN_AI_RESPONSE_TEXT not in tool_exec_span .get ("data" , {})
231
244
245
+ # Verify tool calls are NOT recorded when PII is disabled
246
+ assert SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans [0 ].get (
247
+ "data" , {}
248
+ ), (
249
+ f"Tool calls should NOT be recorded when send_default_pii={ send_default_pii } "
250
+ f"and include_prompts={ include_prompts } "
251
+ )
252
+ assert SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS not in chat_spans [1 ].get (
253
+ "data" , {}
254
+ ), (
255
+ f"Tool calls should NOT be recorded when send_default_pii={ send_default_pii } "
256
+ f"and include_prompts={ include_prompts } "
257
+ )
258
+
259
+ # Verify that available tools are always recorded regardless of PII settings
260
+ for chat_span in chat_spans :
261
+ span_data = chat_span .get ("data" , {})
262
+ if SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS in span_data :
263
+ tools_data = span_data [SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS ]
264
+ assert (
265
+ tools_data is not None
266
+ ), "Available tools should always be recorded regardless of PII settings"
267
+
232
268
233
269
def test_langchain_error (sentry_init , capture_events ):
234
270
sentry_init (
0 commit comments