@@ -19,7 +19,7 @@ async def __call__(self, *args, **kwargs):
19
19
from anthropic .types .message_delta_event import MessageDeltaEvent
20
20
from anthropic .types .message_start_event import MessageStartEvent
21
21
22
- from sentry_sdk .utils import package_version
22
+ from sentry_sdk .utils import _serialize_span_attribute , package_version
23
23
24
24
try :
25
25
from anthropic .types import InputJSONDelta
@@ -115,10 +115,12 @@ def test_nonstreaming_create_message(
115
115
assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
116
116
117
117
if send_default_pii and include_prompts :
118
- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == messages
119
- assert span ["data" ][SPANDATA .AI_RESPONSES ] == [
120
- {"type" : "text" , "text" : "Hi, I'm Claude." }
121
- ]
118
+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (
119
+ messages
120
+ )
121
+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
122
+ [{"type" : "text" , "text" : "Hi, I'm Claude." }]
123
+ )
122
124
else :
123
125
assert SPANDATA .AI_INPUT_MESSAGES not in span ["data" ]
124
126
assert SPANDATA .AI_RESPONSES not in span ["data" ]
@@ -183,10 +185,12 @@ async def test_nonstreaming_create_message_async(
183
185
assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
184
186
185
187
if send_default_pii and include_prompts :
186
- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == messages
187
- assert span ["data" ][SPANDATA .AI_RESPONSES ] == [
188
- {"type" : "text" , "text" : "Hi, I'm Claude." }
189
- ]
188
+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (
189
+ messages
190
+ )
191
+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
192
+ [{"type" : "text" , "text" : "Hi, I'm Claude." }]
193
+ )
190
194
else :
191
195
assert SPANDATA .AI_INPUT_MESSAGES not in span ["data" ]
192
196
assert SPANDATA .AI_RESPONSES not in span ["data" ]
@@ -282,10 +286,12 @@ def test_streaming_create_message(
282
286
assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
283
287
284
288
if send_default_pii and include_prompts :
285
- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == messages
286
- assert span ["data" ][SPANDATA .AI_RESPONSES ] == [
287
- {"type" : "text" , "text" : "Hi! I'm Claude!" }
288
- ]
289
+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (
290
+ messages
291
+ )
292
+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
293
+ [{"type" : "text" , "text" : "Hi! I'm Claude!" }]
294
+ )
289
295
290
296
else :
291
297
assert SPANDATA .AI_INPUT_MESSAGES not in span ["data" ]
@@ -385,10 +391,12 @@ async def test_streaming_create_message_async(
385
391
assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
386
392
387
393
if send_default_pii and include_prompts :
388
- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == messages
389
- assert span ["data" ][SPANDATA .AI_RESPONSES ] == [
390
- {"type" : "text" , "text" : "Hi! I'm Claude!" }
391
- ]
394
+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (
395
+ messages
396
+ )
397
+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
398
+ [{"type" : "text" , "text" : "Hi! I'm Claude!" }]
399
+ )
392
400
393
401
else :
394
402
assert SPANDATA .AI_INPUT_MESSAGES not in span ["data" ]
@@ -515,10 +523,12 @@ def test_streaming_create_message_with_input_json_delta(
515
523
assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
516
524
517
525
if send_default_pii and include_prompts :
518
- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == messages
519
- assert span ["data" ][SPANDATA .AI_RESPONSES ] == [
520
- {"text" : "" , "type" : "text" }
521
- ] # we do not record InputJSONDelta because it could contain PII
526
+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (
527
+ messages
528
+ )
529
+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
530
+ [{"type" : "text" , "text" : "" }]
531
+ ) # we do not record InputJSONDelta because it could contain PII
522
532
523
533
else :
524
534
assert SPANDATA .AI_INPUT_MESSAGES not in span ["data" ]
@@ -652,10 +662,12 @@ async def test_streaming_create_message_with_input_json_delta_async(
652
662
assert span ["data" ][SPANDATA .AI_MODEL_ID ] == "model"
653
663
654
664
if send_default_pii and include_prompts :
655
- assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == messages
656
- assert span ["data" ][SPANDATA .AI_RESPONSES ] == [
657
- {"text" : "" , "type" : "text" }
658
- ] # we do not record InputJSONDelta because it could contain PII
665
+ assert span ["data" ][SPANDATA .AI_INPUT_MESSAGES ] == _serialize_span_attribute (
666
+ messages
667
+ )
668
+ assert span ["data" ][SPANDATA .AI_RESPONSES ] == _serialize_span_attribute (
669
+ [{"type" : "text" , "text" : "" }]
670
+ ) # we do not record InputJSONDelta because it could contain PII
659
671
660
672
else :
661
673
assert SPANDATA .AI_INPUT_MESSAGES not in span ["data" ]
@@ -667,6 +679,7 @@ async def test_streaming_create_message_with_input_json_delta_async(
667
679
assert span ["data" ]["ai.streaming" ] is True
668
680
669
681
682
+ @pytest .mark .forked
670
683
def test_exception_message_create (sentry_init , capture_events ):
671
684
sentry_init (integrations = [AnthropicIntegration ()], traces_sample_rate = 1.0 )
672
685
events = capture_events ()
0 commit comments