@@ -1351,61 +1351,3 @@ def __init__(self, content, message_type="human"):
13511351 # Verify no "ai" roles remain
13521352 roles = [msg ["role" ] for msg in stored_messages if "role" in msg ]
13531353 assert "ai" not in roles
1354-
1355-
1356- def test_langgraph_message_truncation (sentry_init , capture_items ):
1357- """Test that large messages are truncated properly in Langgraph integration."""
1358- import json
1359-
1360- sentry_init (
1361- integrations = [LanggraphIntegration (include_prompts = True )],
1362- traces_sample_rate = 1.0 ,
1363- send_default_pii = True ,
1364- )
1365- items = capture_items ("transaction" , "span" )
1366-
1367- large_content = (
1368- "This is a very long message that will exceed our size limits. " * 1000
1369- )
1370- test_state = {
1371- "messages" : [
1372- MockMessage ("small message 1" , name = "user" ),
1373- MockMessage (large_content , name = "assistant" ),
1374- MockMessage (large_content , name = "user" ),
1375- MockMessage ("small message 4" , name = "assistant" ),
1376- MockMessage ("small message 5" , name = "user" ),
1377- ]
1378- }
1379-
1380- pregel = MockPregelInstance ("test_graph" )
1381-
1382- def original_invoke (self , * args , ** kwargs ):
1383- return {"messages" : args [0 ].get ("messages" , [])}
1384-
1385- with start_transaction ():
1386- wrapped_invoke = _wrap_pregel_invoke (original_invoke )
1387- result = wrapped_invoke (pregel , test_state )
1388-
1389- assert result is not None
1390-
1391- spans = [item .payload for item in items if item .type == "span" ]
1392- invoke_spans = [
1393- span
1394- for span in spans
1395- if span ["attributes" ].get ("sentry.op" ) == OP .GEN_AI_INVOKE_AGENT
1396- ]
1397- assert len (invoke_spans ) > 0
1398-
1399- invoke_span = invoke_spans [0 ]
1400- assert SPANDATA .GEN_AI_REQUEST_MESSAGES in invoke_span ["attributes" ]
1401-
1402- messages_data = invoke_span ["attributes" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
1403- assert isinstance (messages_data , str )
1404-
1405- parsed_messages = json .loads (messages_data )
1406- assert isinstance (parsed_messages , list )
1407- assert len (parsed_messages ) == 1
1408- assert "small message 5" in str (parsed_messages [0 ])
1409-
1410- (tx ,) = (item .payload for item in items if item .type == "transaction" )
1411- assert tx ["_meta" ]["spans" ]["0" ]["data" ]["gen_ai.request.messages" ]["" ]["len" ] == 5
0 commit comments