@@ -2478,56 +2478,6 @@ def mock_messages_create(*args, **kwargs):
24782478 assert stored_messages [0 ]["role" ] == expected_role
24792479
24802480
2481- @pytest .mark .asyncio
2482- async def test_anthropic_message_truncation_async (sentry_init , capture_items ):
2483- """Test that large messages are truncated properly in Anthropic integration."""
2484- sentry_init (
2485- integrations = [AnthropicIntegration (include_prompts = True )],
2486- traces_sample_rate = 1.0 ,
2487- send_default_pii = True ,
2488- )
2489- items = capture_items ("transaction" , "span" )
2490-
2491- client = AsyncAnthropic (api_key = "z" )
2492- client .messages ._post = mock .AsyncMock (return_value = EXAMPLE_MESSAGE )
2493-
2494- large_content = (
2495- "This is a very long message that will exceed our size limits. " * 1000
2496- )
2497- messages = [
2498- {"role" : "user" , "content" : "small message 1" },
2499- {"role" : "assistant" , "content" : large_content },
2500- {"role" : "user" , "content" : large_content },
2501- {"role" : "assistant" , "content" : "small message 4" },
2502- {"role" : "user" , "content" : "small message 5" },
2503- ]
2504-
2505- with start_transaction ():
2506- await client .messages .create (max_tokens = 1024 , messages = messages , model = "model" )
2507-
2508- spans = [item .payload for item in items if item .type == "span" ]
2509- chat_spans = [
2510- span for span in spans if span ["attributes" ].get ("sentry.op" ) == OP .GEN_AI_CHAT
2511- ]
2512- assert len (chat_spans ) > 0
2513-
2514- chat_span = chat_spans [0 ]
2515- assert chat_span ["attributes" ][SPANDATA .GEN_AI_SYSTEM ] == "anthropic"
2516- assert chat_span ["attributes" ][SPANDATA .GEN_AI_OPERATION_NAME ] == "chat"
2517- assert SPANDATA .GEN_AI_REQUEST_MESSAGES in chat_span ["attributes" ]
2518-
2519- messages_data = chat_span ["attributes" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
2520- assert isinstance (messages_data , str )
2521-
2522- parsed_messages = json .loads (messages_data )
2523- assert isinstance (parsed_messages , list )
2524- assert len (parsed_messages ) == 1
2525- assert "small message 5" in str (parsed_messages [0 ])
2526-
2527- tx = next (item .payload for item in items if item .type == "transaction" )
2528- assert tx ["_meta" ]["spans" ]["0" ]["data" ]["gen_ai.request.messages" ]["" ]["len" ] == 5
2529-
2530-
25312481@pytest .mark .parametrize (
25322482 "send_default_pii, include_prompts" ,
25332483 [
0 commit comments