feat(asgi): Migrate away from event processor in span first #5920
3 issues
code-review: Found 3 issues (1 high, 2 medium)
High
Iterating over dict without .items() will cause ValueError at runtime - `sentry_sdk/integrations/asgi.py:310-311`
The code iterates over _get_request_attributes(scope) using for attribute, value in ..., but _get_request_attributes returns a dict[str, Any]. Iterating directly over a dict yields only its keys (strings), not key-value pairs. Python will raise ValueError: too many values to unpack or ValueError: not enough values to unpack when trying to unpack single string keys into two variables. This will cause a runtime crash on every ASGI request when span streaming is not enabled.
Medium
Attribute value is a dict but AttributeValue type does not support dicts - `sentry_sdk/integrations/_asgi_common.py:135`
The client.address attribute is assigned a dictionary value {"REMOTE_ADDR": _get_ip(asgi_scope)}, but the AttributeValue type (defined in _types.py:224-237) only supports primitive types (str, bool, float, int) and their lists/tuples. This type mismatch will likely cause issues when the attribute is serialized or processed by Sentry's telemetry system. The value should be a simple string like _get_ip(asgi_scope) instead.
Inconsistent return type for segment source - returns enum or string depending on code path - `sentry_sdk/integrations/asgi.py:452`
The _get_segment_name_and_source method has inconsistent return types for the source value. Line 452 initializes source as a SegmentSource enum from SEGMENT_SOURCE_FOR_STYLE[segment_style]. However, fallback branches (lines 464, 476, 480) assign SegmentSource.*.value (strings). When an endpoint or route is successfully found (lines 460-461 or 472-473), the source enum is returned unchanged. When used at line 355 with span.set_attribute("sentry.span.source", source), this causes the attribute to sometimes be set to an enum object and sometimes a string, leading to inconsistent telemetry data.
Duration: 7m 6s · Tokens: 524.3k in / 8.3k out · Cost: $1.02 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.01)
Annotations
Check failure on line 311 in sentry_sdk/integrations/asgi.py
sentry-warden / warden: code-review
Iterating over dict without .items() will cause ValueError at runtime
The code iterates over `_get_request_attributes(scope)` using `for attribute, value in ...`, but `_get_request_attributes` returns a `dict[str, Any]`. Iterating directly over a dict yields only its keys (strings), not key-value pairs. Python will raise `ValueError: too many values to unpack` or `ValueError: not enough values to unpack` when trying to unpack single string keys into two variables. This will cause a runtime crash on every ASGI request when span streaming is not enabled.
Check warning on line 135 in sentry_sdk/integrations/_asgi_common.py
sentry-warden / warden: code-review
Attribute value is a dict but AttributeValue type does not support dicts
The `client.address` attribute is assigned a dictionary value `{"REMOTE_ADDR": _get_ip(asgi_scope)}`, but the `AttributeValue` type (defined in `_types.py:224-237`) only supports primitive types (str, bool, float, int) and their lists/tuples. This type mismatch will likely cause issues when the attribute is serialized or processed by Sentry's telemetry system. The value should be a simple string like `_get_ip(asgi_scope)` instead.
Check warning on line 452 in sentry_sdk/integrations/asgi.py
sentry-warden / warden: code-review
Inconsistent return type for segment source - returns enum or string depending on code path
The `_get_segment_name_and_source` method has inconsistent return types for the `source` value. Line 452 initializes `source` as a `SegmentSource` enum from `SEGMENT_SOURCE_FOR_STYLE[segment_style]`. However, fallback branches (lines 464, 476, 480) assign `SegmentSource.*.value` (strings). When an endpoint or route is successfully found (lines 460-461 or 472-473), the source enum is returned unchanged. When used at line 355 with `span.set_attribute("sentry.span.source", source)`, this causes the attribute to sometimes be set to an enum object and sometimes a string, leading to inconsistent telemetry data.