feat(redis): Support streaming spans #6083
3 issues
code-review: Found 3 issues (1 high, 1 medium, 1 low)
High
Span leaks when Redis command throws exception - `sentry_sdk/integrations/redis/_async_common.py:145-147`
The _sentry_execute_command function manually enters db_span and cache_span contexts (lines 126 and 145) but doesn't use try/finally to ensure __exit__ is called on exceptions. If await old_execute_command() raises an exception, the spans' __exit__ methods are never called, causing span leaks and potentially corrupting scope state. The synchronous version in _sync_common.py correctly uses try/finally for this pattern.
Medium
NameError raised when Redis command fails with exception - `sentry_sdk/integrations/redis/_sync_common.py:158`
In sentry_patched_execute_command, when old_execute_command raises an exception, the value variable is never assigned. The finally block then attempts to use value in _set_cache_data(cache_span, self, cache_properties, value), causing a NameError. While capture_internal_exceptions() catches this, it results in unnecessary internal exception noise and obscures the real error from monitoring.
Low
Missing test coverage for StreamedSpan code path in Redis cache module - `sentry_sdk/integrations/redis/modules/caches.py:89-92`
The new StreamedSpan code path in _set_cache_data lacks dedicated test coverage. Existing Redis tests do not include tests with _experiments={"trace_lifecycle": "stream"} enabled. While the implementation correctly uses isinstance checks to differentiate span types and both set_attribute and set_data have compatible signatures, the new streaming path is untested.
Duration: 3m 54s · Tokens: 1.5M in / 15.2k out · Cost: $1.85 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.00)
Annotations
Check failure on line 147 in sentry_sdk/integrations/redis/_async_common.py
sentry-warden / warden: code-review
Span leaks when Redis command throws exception
The `_sentry_execute_command` function manually enters `db_span` and `cache_span` contexts (lines 126 and 145) but doesn't use try/finally to ensure `__exit__` is called on exceptions. If `await old_execute_command()` raises an exception, the spans' `__exit__` methods are never called, causing span leaks and potentially corrupting scope state. The synchronous version in `_sync_common.py` correctly uses try/finally for this pattern.
Check warning on line 158 in sentry_sdk/integrations/redis/_sync_common.py
sentry-warden / warden: code-review
NameError raised when Redis command fails with exception
In `sentry_patched_execute_command`, when `old_execute_command` raises an exception, the `value` variable is never assigned. The `finally` block then attempts to use `value` in `_set_cache_data(cache_span, self, cache_properties, value)`, causing a `NameError`. While `capture_internal_exceptions()` catches this, it results in unnecessary internal exception noise and obscures the real error from monitoring.