@@ -20,7 +20,7 @@ async def __call__(self, *args, **kwargs):
2020from anthropic .types .message_delta_event import MessageDeltaEvent
2121from anthropic .types .message_start_event import MessageStartEvent
2222
23- from sentry_sdk .integrations .anthropic import _add_ai_data_to_span , _collect_ai_data
23+ from sentry_sdk .integrations .anthropic import _set_output_data , _collect_ai_data
2424from sentry_sdk .utils import package_version
2525
2626try :
@@ -692,7 +692,6 @@ async def test_streaming_create_message_with_input_json_delta_async(
692692 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_STREAMING ] is True
693693
694694
695- @pytest .mark .forked
696695def test_exception_message_create (sentry_init , capture_events ):
697696 sentry_init (integrations = [AnthropicIntegration ()], traces_sample_rate = 1.0 )
698697 events = capture_events ()
@@ -814,7 +813,7 @@ def test_collect_ai_data_with_input_json_delta():
814813 ANTHROPIC_VERSION < (0 , 27 ),
815814 reason = "Versions <0.27.0 do not include InputJSONDelta." ,
816815)
817- def test_add_ai_data_to_span_with_input_json_delta (sentry_init , capture_events ):
816+ def test_set_output_data_with_input_json_delta (sentry_init , capture_events ):
818817 sentry_init (
819818 integrations = [AnthropicIntegration (include_prompts = True )],
820819 traces_sample_rate = 1.0 ,
@@ -825,24 +824,24 @@ def test_add_ai_data_to_span_with_input_json_delta(sentry_init, capture_events):
825824 with start_span (name = "test" ):
826825 with start_span (name = "anthropic" ) as span :
827826 integration = AnthropicIntegration ()
828-
829- _add_ai_data_to_span (
827+ json_deltas = [ "{'test': 'data'," , "'more': 'json'}" ]
828+ _set_output_data (
830829 span ,
831830 integration ,
831+ model = "" ,
832832 input_tokens = 10 ,
833833 output_tokens = 20 ,
834- content_blocks = ["{'test': 'data'," , "'more': 'json'}" ],
834+ content_blocks = [{ "text" : "" . join ( json_deltas ) , "type" : "text" } ],
835835 )
836836
837- (event ,) = events
838-
839- assert len (event ["spans" ]) == 1
840- (span ,) = event ["spans" ]
837+ assert len (events ) == 1
838+ root_span = events [0 ]
839+ span = root_span ["spans" ][0 ]
841840
842841 assert (
843- span . _data .get (SPANDATA .GEN_AI_RESPONSE_TEXT )
842+ span [ "data" ] .get (SPANDATA .GEN_AI_RESPONSE_TEXT )
844843 == "[{\" text\" : \" {'test': 'data','more': 'json'}\" , \" type\" : \" text\" }]"
845844 )
846- assert span . _data .get (SPANDATA .GEN_AI_USAGE_INPUT_TOKENS ) == 10
847- assert span . _data .get (SPANDATA .GEN_AI_USAGE_OUTPUT_TOKENS ) == 20
848- assert span . _data .get (SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ) == 30
845+ assert span [ "data" ] .get (SPANDATA .GEN_AI_USAGE_INPUT_TOKENS ) == 10
846+ assert span [ "data" ] .get (SPANDATA .GEN_AI_USAGE_OUTPUT_TOKENS ) == 20
847+ assert span [ "data" ] .get (SPANDATA .GEN_AI_USAGE_TOTAL_TOKENS ) == 30
0 commit comments