Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ class SDKInfo(TypedDict):
"boolean",
"double",
"integer",
"string[]",
"boolean[]",
"double[]",
"integer[]",
"array",
],
"value": AttributeValue,
},
Expand Down
13 changes: 3 additions & 10 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,19 +2097,12 @@ def serialize_attribute(val: "AttributeValue") -> "SerializedAttributeValue":

if isinstance(val, list):
if not val:
return {"value": [], "type": "string[]"}
return {"value": [], "type": "array"}

# Only lists of elements of a single type are supported
list_types: 'dict[type, Literal["string[]", "integer[]", "double[]", "boolean[]"]]' = {
str: "string[]",
int: "integer[]",
float: "double[]",
bool: "boolean[]",
}

ty = type(val[0])
if ty in list_types and all(type(v) is ty for v in val):
return {"value": val, "type": list_types[ty]}
if ty in (int, str, bool, float) and all(type(v) is ty for v in val):
return {"value": val, "type": "array"}

# Coerce to string if we don't know what to do with the value. This should
# never happen as we pre-format early in format_attribute, but let's be safe.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):

assert serialized_attributes["string_list"] == {
"value": ["value1", "value2"],
"type": "string[]",
"type": "array",
}
assert serialized_attributes["int_tuple"] == {
"value": [3, 2, 1, 4],
"type": "integer[]",
"type": "array",
}
assert serialized_attributes["inhomogeneous_tuple"] == {
"value": "(3, 2.0, 1, 4)",
Expand All @@ -705,11 +705,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):

assert serialized_attributes["float_list"] == {
"value": [3.0, 3.5, 4.2],
"type": "double[]",
"type": "array",
}
assert serialized_attributes["bool_tuple"] == {
"value": [False, False, True],
"type": "boolean[]",
"type": "array",
}
assert serialized_attributes["inhomogeneous_list"] == {
"value": "[3.2, True, None]",
Expand Down
8 changes: 4 additions & 4 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):

assert serialized_attributes["string_list.attribute"] == {
"value": ["value1", "value2"],
"type": "string[]",
"type": "array",
}
assert serialized_attributes["int_tuple.attribute"] == {
"value": [3, 2, 1, 4],
"type": "integer[]",
"type": "array",
}
assert serialized_attributes["inhomogeneous_tuple.attribute"] == {
"value": "(3, 2.0, 1, 4)",
Expand All @@ -438,11 +438,11 @@ def test_log_array_attributes(sentry_init, capture_envelopes):

assert serialized_attributes["float_list.attribute"] == {
"value": [3.0, 3.5, 4.2],
"type": "double[]",
"type": "array",
}
assert serialized_attributes["bool_tuple.attribute"] == {
"value": [False, False, True],
"type": "boolean[]",
"type": "array",
}
assert serialized_attributes["inhomogeneous_list.attribute"] == {
"value": "[3.2, True, None]",
Expand Down
Loading