[do not merge] feat: Span streaming & new span API #5551
4 issues
code-review: Found 4 issues (2 high, 1 medium, 1 low)
High
UnboundLocalError when Redis command raises exception - `sentry_sdk/integrations/redis/_sync_common.py:158`
In sentry_patched_execute_command, if old_execute_command raises an exception, the finally block will attempt to access value in the call to _set_cache_data(cache_span, self, cache_properties, value), but value was never assigned. This causes an UnboundLocalError: local variable 'value' referenced before assignment, which will crash the application instead of propagating the original Redis exception.
Also found at:
sentry_sdk/integrations/redis/_async_common.py:145-147
StreamedSpan.set_status() method does not exist, causing AttributeError at runtime - `sentry_sdk/integrations/sqlalchemy.py:102`
The code calls span.set_status(SpanStatus.ERROR) on line 102 when the span is a StreamedSpan. However, StreamedSpan class (defined in sentry_sdk/traces.py) does not have a set_status() method - it only has a status property setter. This will raise an AttributeError at runtime when a SQL error occurs in streaming mode. The fix should use property assignment: span.status = SpanStatus.ERROR.
Also found at:
sentry_sdk/integrations/graphene.py:174-175
Medium
HTTP status code not recorded for StreamedSpan in stdlib httplib integration - `sentry_sdk/integrations/stdlib.py:175-177`
When using span streaming mode, the HTTP status code (e.g., 200, 404, 500) is not recorded as an attribute on the span. Only the status ('ok'/'error') and 'reason' are set. Compare with wsgi.py line 235 which correctly calls span.set_attribute("http.response.status_code", status_int) for StreamedSpan. This results in data loss - users won't see the actual HTTP status code in their traces when using span streaming mode.
Low
Span name 'subprocess popen' is incorrect for subprocess.wait operation - `sentry_sdk/integrations/stdlib.py:322`
The sentry_patched_popen_wait function incorrectly sets the span name to 'subprocess popen' when it should be 'subprocess wait' to match the OP.SUBPROCESS_WAIT operation and the method being wrapped. This inconsistency will make it harder to identify subprocess.wait spans in the Sentry UI, as the span name won't match the operation being performed.
Duration: 10m 43s · Tokens: 8.6M in / 98.6k out · Cost: $12.08 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.01)
Annotations
Check failure on line 158 in sentry_sdk/integrations/redis/_sync_common.py
sentry-warden / warden: code-review
UnboundLocalError when Redis command raises exception
In `sentry_patched_execute_command`, if `old_execute_command` raises an exception, the `finally` block will attempt to access `value` in the call to `_set_cache_data(cache_span, self, cache_properties, value)`, but `value` was never assigned. This causes an `UnboundLocalError: local variable 'value' referenced before assignment`, which will crash the application instead of propagating the original Redis exception.
Check failure on line 147 in sentry_sdk/integrations/redis/_async_common.py
sentry-warden / warden: code-review
[JHF-5NU] UnboundLocalError when Redis command raises exception (additional location)
In `sentry_patched_execute_command`, if `old_execute_command` raises an exception, the `finally` block will attempt to access `value` in the call to `_set_cache_data(cache_span, self, cache_properties, value)`, but `value` was never assigned. This causes an `UnboundLocalError: local variable 'value' referenced before assignment`, which will crash the application instead of propagating the original Redis exception.
Check failure on line 102 in sentry_sdk/integrations/sqlalchemy.py
sentry-warden / warden: code-review
StreamedSpan.set_status() method does not exist, causing AttributeError at runtime
The code calls `span.set_status(SpanStatus.ERROR)` on line 102 when the span is a `StreamedSpan`. However, `StreamedSpan` class (defined in `sentry_sdk/traces.py`) does not have a `set_status()` method - it only has a `status` property setter. This will raise an `AttributeError` at runtime when a SQL error occurs in streaming mode. The fix should use property assignment: `span.status = SpanStatus.ERROR`.
Check failure on line 175 in sentry_sdk/integrations/graphene.py
sentry-warden / warden: code-review
[9YY-XF2] StreamedSpan.set_status() method does not exist, causing AttributeError at runtime (additional location)
The code calls `span.set_status(SpanStatus.ERROR)` on line 102 when the span is a `StreamedSpan`. However, `StreamedSpan` class (defined in `sentry_sdk/traces.py`) does not have a `set_status()` method - it only has a `status` property setter. This will raise an `AttributeError` at runtime when a SQL error occurs in streaming mode. The fix should use property assignment: `span.status = SpanStatus.ERROR`.
Check warning on line 177 in sentry_sdk/integrations/stdlib.py
sentry-warden / warden: code-review
HTTP status code not recorded for StreamedSpan in stdlib httplib integration
When using span streaming mode, the HTTP status code (e.g., 200, 404, 500) is not recorded as an attribute on the span. Only the status ('ok'/'error') and 'reason' are set. Compare with wsgi.py line 235 which correctly calls `span.set_attribute("http.response.status_code", status_int)` for StreamedSpan. This results in data loss - users won't see the actual HTTP status code in their traces when using span streaming mode.