Skip to content

Commit bbac363

Browse files
committed
Use util for serialization
1 parent e1804a8 commit bbac363

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from functools import wraps
2-
import json
32
from typing import TYPE_CHECKING
43

54
import sentry_sdk
@@ -8,6 +7,7 @@
87
from sentry_sdk.integrations import DidNotEnable, Integration
98
from sentry_sdk.scope import should_send_default_pii
109
from sentry_sdk.utils import (
10+
_serialize_span_attribute,
1111
capture_internal_exceptions,
1212
event_from_exception,
1313
package_version,
@@ -88,7 +88,7 @@ def _get_responses(content):
8888
"text": item.text,
8989
}
9090
)
91-
return json.dumps(responses)
91+
return _serialize_span_attribute(responses)
9292

9393

9494
def _collect_ai_data(event, input_tokens, output_tokens, content_blocks):
@@ -127,7 +127,7 @@ def _add_ai_data_to_span(
127127
complete_message = "".join(content_blocks)
128128
span.set_data(
129129
SPANDATA.AI_RESPONSES,
130-
json.dumps([{"type": "text", "text": complete_message}]),
130+
_serialize_span_attribute([{"type": "text", "text": complete_message}]),
131131
)
132132
total_tokens = input_tokens + output_tokens
133133
record_token_usage(span, input_tokens, output_tokens, total_tokens)
@@ -166,7 +166,7 @@ def _sentry_patched_create_common(f, *args, **kwargs):
166166
span.set_data(SPANDATA.AI_STREAMING, False)
167167

168168
if should_send_default_pii() and integration.include_prompts:
169-
span.set_data(SPANDATA.AI_INPUT_MESSAGES, json.dumps(messages))
169+
span.set_data(SPANDATA.AI_INPUT_MESSAGES, _serialize_span_attribute(messages))
170170

171171
if hasattr(result, "content"):
172172
if should_send_default_pii() and integration.include_prompts:

0 commit comments

Comments
 (0)