|
1 | 1 | from functools import wraps |
2 | | -import json |
3 | 2 | from typing import TYPE_CHECKING |
4 | 3 |
|
5 | 4 | import sentry_sdk |
|
8 | 7 | from sentry_sdk.integrations import DidNotEnable, Integration |
9 | 8 | from sentry_sdk.scope import should_send_default_pii |
10 | 9 | from sentry_sdk.utils import ( |
| 10 | + _serialize_span_attribute, |
11 | 11 | capture_internal_exceptions, |
12 | 12 | event_from_exception, |
13 | 13 | package_version, |
@@ -88,7 +88,7 @@ def _get_responses(content): |
88 | 88 | "text": item.text, |
89 | 89 | } |
90 | 90 | ) |
91 | | - return json.dumps(responses) |
| 91 | + return _serialize_span_attribute(responses) |
92 | 92 |
|
93 | 93 |
|
94 | 94 | def _collect_ai_data(event, input_tokens, output_tokens, content_blocks): |
@@ -127,7 +127,7 @@ def _add_ai_data_to_span( |
127 | 127 | complete_message = "".join(content_blocks) |
128 | 128 | span.set_data( |
129 | 129 | SPANDATA.AI_RESPONSES, |
130 | | - json.dumps([{"type": "text", "text": complete_message}]), |
| 130 | + _serialize_span_attribute([{"type": "text", "text": complete_message}]), |
131 | 131 | ) |
132 | 132 | total_tokens = input_tokens + output_tokens |
133 | 133 | record_token_usage(span, input_tokens, output_tokens, total_tokens) |
@@ -166,7 +166,7 @@ def _sentry_patched_create_common(f, *args, **kwargs): |
166 | 166 | span.set_data(SPANDATA.AI_STREAMING, False) |
167 | 167 |
|
168 | 168 | 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)) |
170 | 170 |
|
171 | 171 | if hasattr(result, "content"): |
172 | 172 | if should_send_default_pii() and integration.include_prompts: |
|
0 commit comments