Skip to content

Commit 6ba5365

Browse files
committed
fallback
1 parent 1912635 commit 6ba5365

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sentry_sdk/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ def get_current_thread_meta(thread=None):
18351835

18361836

18371837
def _serialize_span_attribute(value):
1838-
# type: (Any) -> AttributeValue
1838+
# type: (Any) -> Optional[AttributeValue]
18391839
"""Serialize an object so that it's OTel-compatible and displays nicely in Sentry."""
18401840
# check for allowed primitives
18411841
if isinstance(value, (int, str, float, bool)):
@@ -1853,4 +1853,7 @@ def _serialize_span_attribute(value):
18531853
try:
18541854
return json.dumps(value)
18551855
except TypeError:
1856-
return str(value)
1856+
try:
1857+
return str(value)
1858+
except Exception:
1859+
return None

tests/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,11 @@ def test_format_timestamp_naive():
904904
assert re.fullmatch(timestamp_regex, format_timestamp(datetime_object))
905905

906906

907+
class NoStr:
908+
def __str__(self):
909+
1 / 0
910+
911+
907912
@pytest.mark.parametrize(
908913
("value", "result"),
909914
(
@@ -923,6 +928,7 @@ def test_format_timestamp_naive():
923928
),
924929
(datetime(2024, 1, 1), "2024-01-01 00:00:00"),
925930
(("meow", "purr"), ["meow", "purr"]),
931+
(NoStr(), None),
926932
),
927933
)
928934
def test_serialize_span_attribute(value, result):

0 commit comments

Comments
 (0)