feat(redis): Support streaming spans #6083
2 issues
find-bugs: Found 2 issues (2 medium)
Medium
Missing exception handling in async _sentry_execute_command causes span leak on Redis errors - `sentry_sdk/integrations/redis/_async_common.py:145-147`
The async _sentry_execute_command function does not wrap the Redis command execution in a try/finally block. When old_execute_command raises an exception, db_span.__exit__() and cache_span.__exit__() are never called, leaving spans unclosed. The sync version in _sync_common.py correctly uses try/finally (lines 151-160).
Also found at:
sentry_sdk/integrations/redis/_async_common.py:147-148
UnboundLocalError when Redis command raises exception - `sentry_sdk/integrations/redis/_sync_common.py:158`
In sentry_patched_execute_command, the finally block calls _set_cache_data(cache_span, self, cache_properties, value) which references value. However, value is only assigned if old_execute_command succeeds. If old_execute_command raises an exception, value is undefined, causing an UnboundLocalError in the finally block. While capture_internal_exceptions() wraps this call and will suppress the error, this still creates an unnecessary exception that gets silently caught, and the span cleanup logic after it (cache_span.__exit__) will still execute successfully.
Duration: 2m 30s · Tokens: 1.1M in / 12.9k out · Cost: $2.20 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.00)
Annotations
Check warning on line 147 in sentry_sdk/integrations/redis/_async_common.py
sentry-warden / warden: find-bugs
Missing exception handling in async _sentry_execute_command causes span leak on Redis errors
The async `_sentry_execute_command` function does not wrap the Redis command execution in a try/finally block. When `old_execute_command` raises an exception, `db_span.__exit__()` and `cache_span.__exit__()` are never called, leaving spans unclosed. The sync version in `_sync_common.py` correctly uses try/finally (lines 151-160).
Check warning on line 148 in sentry_sdk/integrations/redis/_async_common.py
sentry-warden / warden: find-bugs
[RSL-HHS] Missing exception handling in async _sentry_execute_command causes span leak on Redis errors (additional location)
The async `_sentry_execute_command` function does not wrap the Redis command execution in a try/finally block. When `old_execute_command` raises an exception, `db_span.__exit__()` and `cache_span.__exit__()` are never called, leaving spans unclosed. The sync version in `_sync_common.py` correctly uses try/finally (lines 151-160).
Check warning on line 158 in sentry_sdk/integrations/redis/_sync_common.py
sentry-warden / warden: find-bugs
UnboundLocalError when Redis command raises exception
In `sentry_patched_execute_command`, the `finally` block calls `_set_cache_data(cache_span, self, cache_properties, value)` which references `value`. However, `value` is only assigned if `old_execute_command` succeeds. If `old_execute_command` raises an exception, `value` is undefined, causing an `UnboundLocalError` in the `finally` block. While `capture_internal_exceptions()` wraps this call and will suppress the error, this still creates an unnecessary exception that gets silently caught, and the span cleanup logic after it (`cache_span.__exit__`) will still execute successfully.