@@ -1345,6 +1345,24 @@ def simple_test_tool(message: str) -> str:
13451345 assert ai_client_span2 ["attributes" ]["gen_ai.request.max_tokens" ] == 100
13461346 assert ai_client_span2 ["attributes" ]["gen_ai.request.messages" ] == safe_serialize (
13471347 [
1348+ {
1349+ "role" : "user" ,
1350+ "content" : [
1351+ {"type" : "text" , "text" : "Please use the simple test tool" }
1352+ ],
1353+ },
1354+ {
1355+ "role" : "assistant" ,
1356+ "content" : [
1357+ {
1358+ "arguments" : '{"message": "hello"}' ,
1359+ "call_id" : "call_123" ,
1360+ "name" : "simple_test_tool" ,
1361+ "type" : "function_call" ,
1362+ "id" : "call_123" ,
1363+ }
1364+ ],
1365+ },
13481366 {
13491367 "role" : "tool" ,
13501368 "content" : [
@@ -2288,7 +2306,6 @@ def test_openai_agents_message_role_mapping(
22882306
22892307 get_response_kwargs = {"input" : [test_message ]}
22902308
2291- from sentry_sdk .integrations .openai_agents .utils import _set_input_data
22922309 from sentry_sdk import start_span
22932310
22942311 with start_span (op = "test" ) as span :
@@ -3036,47 +3053,6 @@ def calculator(a: int, b: int) -> int:
30363053 )
30373054
30383055
3039- def test_openai_agents_message_truncation (sentry_init , capture_items ):
3040- """Test that large messages are truncated properly in OpenAI Agents integration."""
3041-
3042- large_content = (
3043- "This is a very long message that will exceed our size limits. " * 1000
3044- )
3045-
3046- sentry_init (
3047- integrations = [OpenAIAgentsIntegration ()],
3048- traces_sample_rate = 1.0 ,
3049- send_default_pii = True ,
3050- )
3051-
3052- test_messages = [
3053- {"role" : "user" , "content" : large_content },
3054- {"role" : "assistant" , "content" : large_content },
3055- {"role" : "user" , "content" : "small message 4" },
3056- {"role" : "assistant" , "content" : "small message 5" },
3057- ]
3058-
3059- get_response_kwargs = {"input" : test_messages }
3060-
3061- with start_span (op = "gen_ai.chat" ) as span :
3062- scope = sentry_sdk .get_current_scope ()
3063- _set_input_data (span , get_response_kwargs )
3064- if hasattr (scope , "_gen_ai_original_message_count" ):
3065- truncated_count = scope ._gen_ai_original_message_count .get (span .span_id )
3066- assert truncated_count == 4 , (
3067- f"Expected 4 original messages, got { truncated_count } "
3068- )
3069-
3070- assert SPANDATA .GEN_AI_REQUEST_MESSAGES in span ._data
3071- messages_data = span ._data [SPANDATA .GEN_AI_REQUEST_MESSAGES ]
3072- assert isinstance (messages_data , str )
3073-
3074- parsed_messages = json .loads (messages_data )
3075- assert isinstance (parsed_messages , list )
3076- assert len (parsed_messages ) == 1
3077- assert "small message 5" in str (parsed_messages [0 ])
3078-
3079-
30803056@pytest .mark .asyncio
30813057async def test_streaming_span_update_captures_response_data (
30823058 sentry_init , test_agent , mock_usage
0 commit comments