Skip to content
Open
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
13 changes: 5 additions & 8 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ class SDKInfo(TypedDict):
Hint = Dict[str, Any]

AttributeValue = (
str | bool | float | int
# TODO: relay support coming soon for
# | list[str] | list[bool] | list[float] | list[int]
str | bool | float | int | list[str] | list[bool] | list[float] | list[int]
)
Attributes = dict[str, AttributeValue]

Comment on lines 217 to 223
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The format_attribute and serialize_attribute functions don't handle list types, causing array attributes to be incorrectly serialized as strings instead of the intended array types.
Severity: CRITICAL

Suggested Fix

Update format_attribute and serialize_attribute in sentry_sdk/utils.py to correctly handle list types. In format_attribute, ensure lists are passed through without modification. In serialize_attribute, add logic to detect lists of primitives (str, bool, int, float) and serialize them to the corresponding array types (string[], boolean[], integer[], double[]). Add unit tests to cover these new array attribute types.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: sentry_sdk/_types.py#L217-L223

Potential issue: The PR introduced support for array types (`list[str]`, `list[int]`,
etc.) in the `AttributeValue` type definition. However, the functions responsible for
processing these attributes, `format_attribute` and `serialize_attribute`, were not
updated. When an array is passed as an attribute, `format_attribute` converts it to its
string representation (e.g., `"['a', 'b']"`) via `safe_repr`. Subsequently,
`serialize_attribute` treats this string as a simple string value, sending `{"type":
"string"}` to the backend instead of the expected array type like `{"type":
"string[]"}`. This leads to silent data corruption for metrics and logs using array
attributes.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, will address tomorrow

Comment on lines 217 to 223
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The functions format_attribute and serialize_attribute do not handle list types, causing array attributes to be incorrectly serialized as strings via safe_repr.
Severity: CRITICAL

Suggested Fix

Update format_attribute and serialize_attribute to properly handle list types. In serialize_attribute, add logic to detect if the value is a list, determine the type of its elements (e.g., int, str), and serialize it to the corresponding array type (e.g., {"value": [1, 2], "type": "integer[]"}). Ensure format_attribute preserves the list type instead of converting it to a string.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: sentry_sdk/_types.py#L217-L223

Potential issue: The pull request updates the `AttributeValue` type to support lists
(e.g., `list[int]`), but the implementation in `format_attribute` and
`serialize_attribute` was not updated to handle them. When an array is passed as an
attribute, `format_attribute` converts it to its string representation using
`safe_repr`. Consequently, `serialize_attribute` treats this value as a string and
serializes it with `{"type": "string"}`. This silently breaks the new array attribute
feature, as the backend receives a string instead of an array, preventing correct
processing and querying.

Did we get this right? 👍 / 👎 to inform future reviews.

Expand All @@ -232,11 +230,10 @@ class SDKInfo(TypedDict):
"boolean",
"double",
"integer",
# TODO: relay support coming soon for:
# "string[]",
# "boolean[]",
# "double[]",
# "integer[]",
"string[]",
"boolean[]",
"double[]",
"integer[]",
],
"value": AttributeValue,
},
Expand Down
Loading