@@ -2325,20 +2325,14 @@ def test_integration_setup(sentry_init):
23252325 assert _failure_callback in (litellm .failure_callback or [])
23262326
23272327
2328- @pytest .mark .parametrize ("stream_gen_ai_spans" , [True , False ])
2329- def test_litellm_message_truncation (
2330- sentry_init ,
2331- capture_events ,
2332- capture_items ,
2333- stream_gen_ai_spans ,
2334- ):
2328+ def test_litellm_message_truncation (sentry_init , capture_events ):
23352329 """Test that large messages are truncated properly in LiteLLM integration."""
23362330 sentry_init (
23372331 integrations = [LiteLLMIntegration (include_prompts = True )],
23382332 traces_sample_rate = 1.0 ,
23392333 send_default_pii = True ,
2340- stream_gen_ai_spans = stream_gen_ai_spans ,
23412334 )
2335+ events = capture_events ()
23422336
23432337 large_content = (
23442338 "This is a very long message that will exceed our size limits. " * 1000
@@ -2352,78 +2346,39 @@ def test_litellm_message_truncation(
23522346 ]
23532347 mock_response = MockCompletionResponse ()
23542348
2355- if stream_gen_ai_spans :
2356- items = capture_items ("transaction" , "span" )
2357-
2358- with start_transaction (name = "litellm test" ):
2359- kwargs = {
2360- "model" : "gpt-3.5-turbo" ,
2361- "messages" : messages ,
2362- }
2363-
2364- _input_callback (kwargs )
2365- _success_callback (
2366- kwargs ,
2367- mock_response ,
2368- datetime .now (),
2369- datetime .now (),
2370- )
2371-
2372- spans = [item .payload for item in items if item .type == "span" ]
2373- chat_spans = [
2374- span
2375- for span in spans
2376- if span ["attributes" ].get ("sentry.op" ) == OP .GEN_AI_CHAT
2377- ]
2378- assert len (chat_spans ) > 0
2379-
2380- chat_span = chat_spans [0 ]
2381- assert SPANDATA .GEN_AI_REQUEST_MESSAGES in chat_span ["attributes" ]
2382-
2383- messages_data = chat_span ["attributes" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
2384- assert isinstance (messages_data , str )
2385-
2386- parsed_messages = json .loads (messages_data )
2387- assert isinstance (parsed_messages , list )
2388- assert len (parsed_messages ) == 1
2389- assert "small message 5" in str (parsed_messages [0 ])
2390- tx = next (item .payload for item in items if item .type == "transaction" )
2391- else :
2392- events = capture_events ()
2393-
2394- with start_transaction (name = "litellm test" ):
2395- kwargs = {
2396- "model" : "gpt-3.5-turbo" ,
2397- "messages" : messages ,
2398- }
2349+ with start_transaction (name = "litellm test" ):
2350+ kwargs = {
2351+ "model" : "gpt-3.5-turbo" ,
2352+ "messages" : messages ,
2353+ }
23992354
2400- _input_callback (kwargs )
2401- _success_callback (
2402- kwargs ,
2403- mock_response ,
2404- datetime .now (),
2405- datetime .now (),
2406- )
2355+ _input_callback (kwargs )
2356+ _success_callback (
2357+ kwargs ,
2358+ mock_response ,
2359+ datetime .now (),
2360+ datetime .now (),
2361+ )
24072362
2408- assert len (events ) > 0
2409- tx = events [0 ]
2410- assert tx ["type" ] == "transaction"
2363+ assert len (events ) > 0
2364+ tx = events [0 ]
2365+ assert tx ["type" ] == "transaction"
24112366
2412- chat_spans = [
2413- span for span in tx .get ("spans" , []) if span .get ("op" ) == OP .GEN_AI_CHAT
2414- ]
2415- assert len (chat_spans ) > 0
2367+ chat_spans = [
2368+ span for span in tx .get ("spans" , []) if span .get ("op" ) == OP .GEN_AI_CHAT
2369+ ]
2370+ assert len (chat_spans ) > 0
24162371
2417- chat_span = chat_spans [0 ]
2418- assert SPANDATA .GEN_AI_REQUEST_MESSAGES in chat_span ["data" ]
2372+ chat_span = chat_spans [0 ]
2373+ assert SPANDATA .GEN_AI_REQUEST_MESSAGES in chat_span ["data" ]
24192374
2420- messages_data = chat_span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
2421- assert isinstance (messages_data , str )
2375+ messages_data = chat_span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
2376+ assert isinstance (messages_data , str )
24222377
2423- parsed_messages = json .loads (messages_data )
2424- assert isinstance (parsed_messages , list )
2425- assert len (parsed_messages ) == 1
2426- assert "small message 5" in str (parsed_messages [0 ])
2378+ parsed_messages = json .loads (messages_data )
2379+ assert isinstance (parsed_messages , list )
2380+ assert len (parsed_messages ) == 1
2381+ assert "small message 5" in str (parsed_messages [0 ])
24272382 assert tx ["_meta" ]["spans" ]["0" ]["data" ]["gen_ai.request.messages" ]["" ]["len" ] == 5
24282383
24292384
0 commit comments