@@ -69,6 +69,7 @@ async def __call__(self, *args, **kwargs):
6969 role = "assistant" ,
7070 content = [TextBlock (type = "text" , text = "Hi, I'm Claude." )],
7171 type = "message" ,
72+ stop_reason = "end_turn" ,
7273 usage = Usage (input_tokens = 10 , output_tokens = 20 ),
7374)
7475
@@ -142,6 +143,7 @@ def test_nonstreaming_create_message(
142143 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
143144 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is False
144145 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
146+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["end_turn" ]
145147
146148
147149@pytest .mark .asyncio
@@ -264,7 +266,7 @@ def test_streaming_create_message(
264266 ),
265267 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
266268 MessageDeltaEvent (
267- delta = Delta (),
269+ delta = Delta (stop_reason = "max_tokens" ),
268270 usage = MessageDeltaUsage (output_tokens = 10 ),
269271 type = "message_delta" ,
270272 ),
@@ -329,6 +331,7 @@ def test_streaming_create_message(
329331 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
330332 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
331333 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
334+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
332335
333336
334337def test_streaming_create_message_next_consumption (
@@ -368,7 +371,7 @@ def test_streaming_create_message_next_consumption(
368371 ),
369372 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
370373 MessageDeltaEvent (
371- delta = Delta (),
374+ delta = Delta (stop_reason = "max_tokens" ),
372375 usage = MessageDeltaUsage (output_tokens = 10 ),
373376 type = "message_delta" ,
374377 ),
@@ -428,6 +431,7 @@ def test_streaming_create_message_next_consumption(
428431 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
429432 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
430433 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
434+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
431435
432436
433437def test_streaming_create_message_iterator_methods (
@@ -467,7 +471,7 @@ def test_streaming_create_message_iterator_methods(
467471 ),
468472 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
469473 MessageDeltaEvent (
470- delta = Delta (),
474+ delta = Delta (stop_reason = "max_tokens" ),
471475 usage = MessageDeltaUsage (output_tokens = 10 ),
472476 type = "message_delta" ,
473477 ),
@@ -580,7 +584,7 @@ def test_stream_messages(
580584 ),
581585 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
582586 MessageDeltaEvent (
583- delta = Delta (),
587+ delta = Delta (stop_reason = "max_tokens" ),
584588 usage = MessageDeltaUsage (output_tokens = 10 ),
585589 type = "message_delta" ,
586590 ),
@@ -646,6 +650,7 @@ def test_stream_messages(
646650 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
647651 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
648652 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
653+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
649654
650655
651656def test_stream_messages_next_consumption (
@@ -685,7 +690,7 @@ def test_stream_messages_next_consumption(
685690 ),
686691 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
687692 MessageDeltaEvent (
688- delta = Delta (),
693+ delta = Delta (stop_reason = "max_tokens" ),
689694 usage = MessageDeltaUsage (output_tokens = 10 ),
690695 type = "message_delta" ,
691696 ),
@@ -746,6 +751,7 @@ def test_stream_messages_next_consumption(
746751 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
747752 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
748753 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
754+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
749755
750756
751757def test_stream_messages_iterator_methods (
@@ -785,7 +791,7 @@ def test_stream_messages_iterator_methods(
785791 ),
786792 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
787793 MessageDeltaEvent (
788- delta = Delta (),
794+ delta = Delta (stop_reason = "max_tokens" ),
789795 usage = MessageDeltaUsage (output_tokens = 10 ),
790796 type = "message_delta" ,
791797 ),
@@ -905,7 +911,7 @@ async def test_streaming_create_message_async(
905911 ),
906912 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
907913 MessageDeltaEvent (
908- delta = Delta (),
914+ delta = Delta (stop_reason = "max_tokens" ),
909915 usage = MessageDeltaUsage (output_tokens = 10 ),
910916 type = "message_delta" ,
911917 ),
@@ -917,6 +923,7 @@ async def test_streaming_create_message_async(
917923 sentry_init (
918924 integrations = [AnthropicIntegration (include_prompts = include_prompts )],
919925 traces_sample_rate = 1.0 ,
926+ default_integrations = False ,
920927 send_default_pii = send_default_pii ,
921928 )
922929 events = capture_events ()
@@ -972,6 +979,7 @@ async def test_streaming_create_message_async(
972979 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 20
973980 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
974981 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
982+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
975983
976984
977985@pytest .mark .asyncio
@@ -1014,7 +1022,7 @@ async def test_streaming_create_message_async_next_consumption(
10141022 ),
10151023 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
10161024 MessageDeltaEvent (
1017- delta = Delta (),
1025+ delta = Delta (stop_reason = "max_tokens" ),
10181026 usage = MessageDeltaUsage (output_tokens = 10 ),
10191027 type = "message_delta" ,
10201028 ),
@@ -1117,7 +1125,7 @@ async def test_streaming_create_message_async_iterator_methods(
11171125 ),
11181126 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
11191127 MessageDeltaEvent (
1120- delta = Delta (),
1128+ delta = Delta (stop_reason = "max_tokens" ),
11211129 usage = MessageDeltaUsage (output_tokens = 10 ),
11221130 type = "message_delta" ,
11231131 ),
@@ -1184,6 +1192,7 @@ async def test_streaming_create_message_async_iterator_methods(
11841192 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
11851193 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
11861194 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
1195+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
11871196
11881197
11891198@pytest .mark .asyncio
@@ -1347,7 +1356,7 @@ async def test_stream_messages_async_next_consumption(
13471356 ),
13481357 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
13491358 MessageDeltaEvent (
1350- delta = Delta (),
1359+ delta = Delta (stop_reason = "max_tokens" ),
13511360 usage = MessageDeltaUsage (output_tokens = 10 ),
13521361 type = "message_delta" ,
13531362 ),
@@ -1451,7 +1460,7 @@ async def test_stream_messages_async_iterator_methods(
14511460 ),
14521461 ContentBlockStopEvent (type = "content_block_stop" , index = 0 ),
14531462 MessageDeltaEvent (
1454- delta = Delta (),
1463+ delta = Delta (stop_reason = "max_tokens" ),
14551464 usage = MessageDeltaUsage (output_tokens = 10 ),
14561465 type = "message_delta" ,
14571466 ),
@@ -1524,6 +1533,7 @@ async def test_stream_messages_async_iterator_methods(
15241533 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
15251534 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
15261535 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_ID ] == "msg_01XFDUDYJgAACzvnptvVoYEL"
1536+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["max_tokens" ]
15271537
15281538
15291539@pytest .mark .skipif (
@@ -2315,14 +2325,15 @@ def test_collect_ai_data_with_input_json_delta():
23152325
23162326 content_blocks = []
23172327
2318- model , new_usage , new_content_blocks , response_id = _collect_ai_data (
2328+ model , new_usage , new_content_blocks , response_id , finish_reason = _collect_ai_data (
23192329 event , model , usage , content_blocks
23202330 )
23212331 assert model is None
23222332 assert new_usage .input_tokens == usage .input_tokens
23232333 assert new_usage .output_tokens == usage .output_tokens
23242334 assert new_content_blocks == ["test" ]
23252335 assert response_id is None
2336+ assert finish_reason is None
23262337
23272338
23282339@pytest .mark .skipif (
@@ -2610,6 +2621,7 @@ def test_nonstreaming_create_message_with_system_prompt(
26102621 assert span ["data" ][SPANDATA .GEN_AI_USAGE_OUTPUT_TOKENS ] == 20
26112622 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
26122623 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is False
2624+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["end_turn" ]
26132625
26142626
26152627@pytest .mark .asyncio
@@ -2695,6 +2707,7 @@ async def test_nonstreaming_create_message_with_system_prompt_async(
26952707 assert span ["data" ][SPANDATA .GEN_AI_USAGE_OUTPUT_TOKENS ] == 20
26962708 assert span ["data" ][SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ] == 30
26972709 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is False
2710+ assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_FINISH_REASONS ] == ["end_turn" ]
26982711
26992712
27002713@pytest .mark .parametrize (
0 commit comments