@@ -63,6 +63,7 @@ async def __call__(self, *args, **kwargs):
6363 role = "assistant" ,
6464 content = [TextBlock (type = "text" , text = "Hi, I'm Claude." )],
6565 type = "message" ,
66+ stop_reason = "end_turn" ,
6667 usage = Usage (input_tokens = 10 , output_tokens = 20 ),
6768)
6869
@@ -136,6 +137,7 @@ def test_nonstreaming_create_message(
136137 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
137138 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is False
138139 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
140+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["end_turn" ]
139141
140142
141143@pytest .mark .asyncio
@@ -258,7 +260,7 @@ def test_streaming_create_message(
258260 ),
259261 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
260262 MessageDeltaEvent (
261- delta = Delta (),
263+ delta = Delta (stop_reason = "max_tokens" ),
262264 usage = MessageDeltaUsage (output_tokens = 10 ),
263265 type = "message_delta" ,
264266 ),
@@ -323,6 +325,7 @@ def test_streaming_create_message(
323325 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
324326 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
325327 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
328+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
326329
327330
328331@pytest .mark .parametrize (
@@ -373,7 +376,7 @@ def test_stream_messages(
373376 ),
374377 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
375378 MessageDeltaEvent (
376- delta = Delta (),
379+ delta = Delta (stop_reason = "max_tokens" ),
377380 usage = MessageDeltaUsage (output_tokens = 10 ),
378381 type = "message_delta" ,
379382 ),
@@ -439,6 +442,7 @@ def test_stream_messages(
439442 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
440443 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
441444 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
445+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
442446
443447
444448@pytest .mark .asyncio
@@ -492,7 +496,7 @@ async def test_streaming_create_message_async(
492496 ),
493497 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
494498 MessageDeltaEvent (
495- delta = Delta (),
499+ delta = Delta (stop_reason = "max_tokens" ),
496500 usage = MessageDeltaUsage (output_tokens = 10 ),
497501 type = "message_delta" ,
498502 ),
@@ -504,6 +508,7 @@ async def test_streaming_create_message_async(
504508 sentry_init (
505509 integrations = [AnthropicIntegration (include_prompts = include_prompts )],
506510 traces_sample_rate = 1.0 ,
511+ default_integrations = False ,
507512 send_default_pii = send_default_pii ,
508513 )
509514 events = capture_events ()
@@ -559,6 +564,7 @@ async def test_streaming_create_message_async(
559564 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
560565 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
561566 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
567+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
562568
563569
564570@pytest .mark .asyncio
@@ -1471,14 +1477,15 @@ def test_collect_ai_data_with_input_json_delta():
14711477
14721478 content_blocks = []
14731479
1474- model , new_usage , new_content_blocks , response_id = _collect_ai_data (
1480+ model , new_usage , new_content_blocks , response_id , finish_reason = _collect_ai_data (
14751481 event , model , usage , content_blocks
14761482 )
14771483 assert model is None
14781484 assert new_usage .input_tokens == usage .input_tokens
14791485 assert new_usage .output_tokens == usage .output_tokens
14801486 assert new_content_blocks == ["test" ]
14811487 assert response_id is None
1488+ assert finish_reason is None
14821489
14831490
14841491@pytest .mark .skipif (
@@ -1766,6 +1773,7 @@ def test_nonstreaming_create_message_with_system_prompt(
17661773 assert span ["data" ][SPANDATA .GEN_AI_USAGE_OUTPUT_TOKENS ] == 20
17671774 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
17681775 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is False
1776+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["end_turn" ]
17691777
17701778
17711779@pytest .mark .asyncio
@@ -1851,6 +1859,7 @@ async def test_nonstreaming_create_message_with_system_prompt_async(
18511859 assert span ["data" ][SPANDATA .GEN_AI_USAGE_OUTPUT_TOKENS ] == 20
18521860 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
18531861 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is False
1862+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["end_turn" ]
18541863
18551864
18561865@pytest .mark .parametrize (
0 commit comments