1- import json
21from unittest import mock
32
43try :
@@ -20,7 +19,7 @@ async def __call__(self, *args, **kwargs):
2019from anthropic .types .message_delta_event import MessageDeltaEvent
2120from anthropic .types .message_start_event import MessageStartEvent
2221
23- from sentry_sdk .utils import package_version
22+ from sentry_sdk .utils import _serialize_span_attribute , package_version
2423
2524try :
2625 from anthropic .types import InputJSONDelta
@@ -116,8 +115,8 @@ def test_nonstreaming_create_message(
116115 assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
117116
118117 if send_default_pii and include_prompts :
119- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == json . dumps (messages )
120- assert span ["data" ][SPANDATA .AI_RESPONSES ] == json . dumps (
118+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (messages )
119+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
121120 [{"type" : "text" , "text" : "Hi, I'm Claude." }]
122121 )
123122 else :
@@ -184,8 +183,8 @@ async def test_nonstreaming_create_message_async(
184183 assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
185184
186185 if send_default_pii and include_prompts :
187- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == json . dumps (messages )
188- assert span ["data" ][SPANDATA .AI_RESPONSES ] == json . dumps (
186+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (messages )
187+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
189188 [{"type" : "text" , "text" : "Hi, I'm Claude." }]
190189 )
191190 else :
@@ -283,8 +282,8 @@ def test_streaming_create_message(
283282 assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
284283
285284 if send_default_pii and include_prompts :
286- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == json . dumps (messages )
287- assert span ["data" ][SPANDATA .AI_RESPONSES ] == json . dumps (
285+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (messages )
286+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
288287 [{"type" : "text" , "text" : "Hi! I'm Claude!" }]
289288 )
290289
@@ -386,8 +385,8 @@ async def test_streaming_create_message_async(
386385 assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
387386
388387 if send_default_pii and include_prompts :
389- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == json . dumps (messages )
390- assert span ["data" ][SPANDATA .AI_RESPONSES ] == json . dumps (
388+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (messages )
389+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
391390 [{"type" : "text" , "text" : "Hi! I'm Claude!" }]
392391 )
393392
@@ -516,8 +515,8 @@ def test_streaming_create_message_with_input_json_delta(
516515 assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
517516
518517 if send_default_pii and include_prompts :
519- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == json . dumps (messages )
520- assert span ["data" ][SPANDATA .AI_RESPONSES ] == json . dumps (
518+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (messages )
519+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
521520 [{"type" : "text" , "text" : "" }]
522521 ) # we do not record InputJSONDelta because it could contain PII
523522
@@ -653,8 +652,8 @@ async def test_streaming_create_message_with_input_json_delta_async(
653652 assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
654653
655654 if send_default_pii and include_prompts :
656- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == json . dumps (messages )
657- assert span ["data" ][SPANDATA .AI_RESPONSES ] == json . dumps (
655+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (messages )
656+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
658657 [{"type" : "text" , "text" : "" }]
659658 ) # we do not record InputJSONDelta because it could contain PII
660659
0 commit comments