Skip to content

Commit 78eca96

Browse files
authored
fix: Fix list attribute type (#5417)
List attributes should be sent over the wire with `type: array` instead of specialized `integer[]`, `string[]` etc. types. We might support non-homogenous arrays in the future.
1 parent 2ffa865 commit 78eca96

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

sentry_sdk/_types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,7 @@ class SDKInfo(TypedDict):
241241
"boolean",
242242
"double",
243243
"integer",
244-
"string[]",
245-
"boolean[]",
246-
"double[]",
247-
"integer[]",
244+
"array",
248245
],
249246
"value": AttributeValue,
250247
},

sentry_sdk/utils.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,19 +2097,12 @@ def serialize_attribute(val: "AttributeValue") -> "SerializedAttributeValue":
20972097

20982098
if isinstance(val, list):
20992099
if not val:
2100-
return {"value": [], "type": "string[]"}
2100+
return {"value": [], "type": "array"}
21012101

21022102
# Only lists of elements of a single type are supported
2103-
list_types: 'dict[type, Literal["string[]", "integer[]", "double[]", "boolean[]"]]' = {
2104-
str: "string[]",
2105-
int: "integer[]",
2106-
float: "double[]",
2107-
bool: "boolean[]",
2108-
}
2109-
21102103
ty = type(val[0])
2111-
if ty in list_types and all(type(v) is ty for v in val):
2112-
return {"value": val, "type": list_types[ty]}
2104+
if ty in (int, str, bool, float) and all(type(v) is ty for v in val):
2105+
return {"value": val, "type": "array"}
21132106

21142107
# Coerce to string if we don't know what to do with the value. This should
21152108
# never happen as we pre-format early in format_attribute, but let's be safe.

tests/test_logs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):
692692

693693
assert serialized_attributes["string_list"] == {
694694
"value": ["value1", "value2"],
695-
"type": "string[]",
695+
"type": "array",
696696
}
697697
assert serialized_attributes["int_tuple"] == {
698698
"value": [3, 2, 1, 4],
699-
"type": "integer[]",
699+
"type": "array",
700700
}
701701
assert serialized_attributes["inhomogeneous_tuple"] == {
702702
"value": "(3, 2.0, 1, 4)",
@@ -705,11 +705,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):
705705

706706
assert serialized_attributes["float_list"] == {
707707
"value": [3.0, 3.5, 4.2],
708-
"type": "double[]",
708+
"type": "array",
709709
}
710710
assert serialized_attributes["bool_tuple"] == {
711711
"value": [False, False, True],
712-
"type": "boolean[]",
712+
"type": "array",
713713
}
714714
assert serialized_attributes["inhomogeneous_list"] == {
715715
"value": "[3.2, True, None]",

tests/test_metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):
425425

426426
assert serialized_attributes["string_list.attribute"] == {
427427
"value": ["value1", "value2"],
428-
"type": "string[]",
428+
"type": "array",
429429
}
430430
assert serialized_attributes["int_tuple.attribute"] == {
431431
"value": [3, 2, 1, 4],
432-
"type": "integer[]",
432+
"type": "array",
433433
}
434434
assert serialized_attributes["inhomogeneous_tuple.attribute"] == {
435435
"value": "(3, 2.0, 1, 4)",
@@ -438,11 +438,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):
438438

439439
assert serialized_attributes["float_list.attribute"] == {
440440
"value": [3.0, 3.5, 4.2],
441-
"type": "double[]",
441+
"type": "array",
442442
}
443443
assert serialized_attributes["bool_tuple.attribute"] == {
444444
"value": [False, False, True],
445-
"type": "boolean[]",
445+
"type": "array",
446446
}
447447
assert serialized_attributes["inhomogeneous_list.attribute"] == {
448448
"value": "[3.2, True, None]",

0 commit comments

Comments
 (0)