feat(redis): Support streaming spans #6083
3 issues
code-review: Found 3 issues (3 medium)
Medium
Spans not closed when Redis command raises exception - `sentry_sdk/integrations/redis/_sync_common.py:151-158`
In sentry_patched_execute_command, spans are entered with __enter__() and exited with __exit__() manually, but if old_execute_command() raises an exception, __exit__() is never called for either db_span or cache_span. This leaves spans unclosed when Redis commands fail, which causes resource leaks and incorrect span hierarchies. The patch_redis_pipeline function uses the with span: pattern correctly, but this function does not.
Test parameters `expected_first_ten` and `send_default_pii` not verified in streaming branch - `tests/integrations/redis/asyncio/test_redis_asyncio.py:66-88`
In the span_streaming=True branch (lines 66-88), the test parameters expected_first_ten and send_default_pii are passed to the test but never verified. The static path verifies these via redis.commands.first_ten assertions. This means PII filtering behavior is not tested in the streaming code path, reducing test coverage for a security-sensitive feature.
Also found at:
tests/integrations/redis/cluster/test_redis_cluster.py:152-153
Test assertion checks wrong span index for cache.hit property - `tests/integrations/redis/test_redis_cache_module_async.py:293`
On line 293, the assertion assert "cache.hit" not in spans[1]["data"] checks spans[1] (the db.redis span from line 286), but should check spans[2] (the cache.put span being validated in the surrounding assertions on lines 288-294). This causes the test to validate the wrong span, making it less reliable for catching regressions in the cache.put functionality.
Also found at:
tests/integrations/redis/test_redis_cache_module.py:330
Duration: 7m 51s · Tokens: 2.8M in / 33.2k out · Cost: $3.92 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.01)
Annotations
Check warning on line 158 in sentry_sdk/integrations/redis/_sync_common.py
sentry-warden / warden: code-review
Spans not closed when Redis command raises exception
In `sentry_patched_execute_command`, spans are entered with `__enter__()` and exited with `__exit__()` manually, but if `old_execute_command()` raises an exception, `__exit__()` is never called for either `db_span` or `cache_span`. This leaves spans unclosed when Redis commands fail, which causes resource leaks and incorrect span hierarchies. The `patch_redis_pipeline` function uses the `with span:` pattern correctly, but this function does not.
Check warning on line 88 in tests/integrations/redis/asyncio/test_redis_asyncio.py
sentry-warden / warden: code-review
Test parameters `expected_first_ten` and `send_default_pii` not verified in streaming branch
In the `span_streaming=True` branch (lines 66-88), the test parameters `expected_first_ten` and `send_default_pii` are passed to the test but never verified. The static path verifies these via `redis.commands.first_ten` assertions. This means PII filtering behavior is not tested in the streaming code path, reducing test coverage for a security-sensitive feature.
Check warning on line 153 in tests/integrations/redis/cluster/test_redis_cluster.py
sentry-warden / warden: code-review
[U63-PXW] Test parameters `expected_first_ten` and `send_default_pii` not verified in streaming branch (additional location)
In the `span_streaming=True` branch (lines 66-88), the test parameters `expected_first_ten` and `send_default_pii` are passed to the test but never verified. The static path verifies these via `redis.commands.first_ten` assertions. This means PII filtering behavior is not tested in the streaming code path, reducing test coverage for a security-sensitive feature.
Check warning on line 293 in tests/integrations/redis/test_redis_cache_module_async.py
sentry-warden / warden: code-review
Test assertion checks wrong span index for cache.hit property
On line 293, the assertion `assert "cache.hit" not in spans[1]["data"]` checks `spans[1]` (the `db.redis` span from line 286), but should check `spans[2]` (the `cache.put` span being validated in the surrounding assertions on lines 288-294). This causes the test to validate the wrong span, making it less reliable for catching regressions in the cache.put functionality.
Check warning on line 330 in tests/integrations/redis/test_redis_cache_module.py
sentry-warden / warden: code-review
[M32-XGH] Test assertion checks wrong span index for cache.hit property (additional location)
On line 293, the assertion `assert "cache.hit" not in spans[1]["data"]` checks `spans[1]` (the `db.redis` span from line 286), but should check `spans[2]` (the `cache.put` span being validated in the surrounding assertions on lines 288-294). This causes the test to validate the wrong span, making it less reliable for catching regressions in the cache.put functionality.