8000 Moved _serialize_span_attribute into set_attribute (#3732) · getsentry/sentry-python@453d152 · GitHub
[go: up one dir, main page]

Skip to content

Commit 453d152

Browse files
authored
Moved _serialize_span_attribute into set_attribute (#3732)
1 parent 0ffc5cd commit 453d152

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from sentry_sdk.integrations import DidNotEnable, Integration
88
from sentry_sdk.scope import should_send_default_pii
99
from sentry_sdk.utils import (
10-
_serialize_span_attribute,
1110
capture_internal_exceptions,
1211
event_from_exception,
1312
package_version,
@@ -127,7 +126,7 @@ def _add_ai_data_to_span(
127126
complete_message = "".join(content_blocks)
128127
span.set_data(
129128
SPANDATA.AI_RESPONSES,
130-
_serialize_span_attribute([{"type": "text", "text": complete_message}]),
129+
[{"type": "text", "text": complete_message}],
131130
)
132131
total_tokens = input_tokens + output_tokens
133132
record_token_usage(span, input_tokens, output_tokens, total_tokens)
@@ -166,16 +165,11 @@ def _sentry_patched_create_common(f, *args, **kwargs):
166165
span.set_data(SPANDATA.AI_STREAMING, False)
167166

168167
if should_send_default_pii() and integration.include_prompts:
169-
span.set_data(
170-
SPANDATA.AI_INPUT_MESSAGES, _serialize_span_attribute(messages)
171-
)
168+
span.set_data(SPANDATA.AI_INPUT_MESSAGES, messages)
172169

173170
if hasattr(result, "content"):
174171
if should_send_default_pii() and integration.include_prompts:
175-
span.set_data(
176-
SPANDATA.AI_RESPONSES,
177-
_serialize_span_attribute(_get_responses(result.content)),
178-
)
172+
span.set_data(SPANDATA.AI_RESPONSES, _get_responses(result.content))
179173
_calculate_token_usage(result, span)
180174
span.__exit__(None, None, None)
181175

sentry_sdk/tracing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from sentry_sdk.consts import SPANSTATUS, SPANDATA
1919
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
2020
from sentry_sdk.utils import (
21+
_serialize_span_attribute,
2122
get_current_thread_meta,
2223
is_valid_sample_rate,
2324
logger,
@@ -1519,7 +1520,7 @@ def get_attribute(self, name):
15191520

15201521
def set_attribute(self, key, value):
15211522
# type: (str, Any) -> None
1522-
self._otel_span.set_attribute(key, value)
1523+
self._otel_span.set_attribute(key, _serialize_span_attribute(value))
15231524

15241525
def set_status(self, status):
15251526
# type: (str) -> None

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
_is_external_source,
2424
_is_in_project_root,
2525
_module_in_list,
26-
_serialize_span_attribute,
2726
)
2827

2928
from typing import TYPE_CHECKING
@@ -134,13 +133,13 @@ def record_sql_queries(
134133

135134
data = {}
136135
if params_list is not None:
137-
data["db.params"] = _serialize_span_attribute(params_list)
136+
data["db.params"] = params_list
138137
if paramstyle is not None:
139-
data["db.paramstyle"] = _serialize_span_attribute(paramstyle)
138+
data["db.paramstyle"] = paramstyle
140139
if executemany:
141140
data["db.executemany"] = True
142141
if record_cursor_repr and cursor is not None:
143-
data["db.cursor"] = _serialize_span_attribute(cursor)
142+
data["db.cursor"] = cursor
144143

145144
with capture_internal_exceptions():
146145
sentry_sdk.add_breadcrumb(message=query, category="query", data=data)

0 commit comments

Comments
 (0)
0