fix: Introduce _get_current_streamed_span() to keep types backwards compatible
#6177
1 issue
find-bugs: Found 1 issue (1 medium)
Medium
streamed_span setter unconditionally overwrites self._span, can clobber an existing Span - `sentry_sdk/scope.py:917`
The new streamed_span setter assigns self._span = span without checking what is currently stored. If the scope currently holds a Span (transaction-mode) and any caller assigns scope.streamed_span = None or a StreamedSpan, the existing Span is silently destroyed. The same asymmetry exists on the span setter for an existing StreamedSpan. Because Scope.span and Scope.streamed_span are documented as type-discriminated views over the same underlying _span, callers reasonably assume that touching one will not affect the other; this assumption does not hold and can lead to lost spans/transactions when both lifecycles are mixed.
Duration: 1m 26s · Tokens: 868.7k in / 12.5k out · Cost: $3.82 (+extraction: $0.00)
Annotations
Check warning on line 917 in sentry_sdk/scope.py
sentry-warden / warden: find-bugs
streamed_span setter unconditionally overwrites self._span, can clobber an existing Span
The new `streamed_span` setter assigns `self._span = span` without checking what is currently stored. If the scope currently holds a `Span` (transaction-mode) and any caller assigns `scope.streamed_span = None` or a StreamedSpan, the existing `Span` is silently destroyed. The same asymmetry exists on the `span` setter for an existing `StreamedSpan`. Because `Scope.span` and `Scope.streamed_span` are documented as type-discriminated views over the same underlying `_span`, callers reasonably assume that touching one will not affect the other; this assumption does not hold and can lead to lost spans/transactions when both lifecycles are mixed.