fix: Introduce _get_current_streamed_span() to keep types backwards compatible
#6177
1 issue
code-review: Found 1 issue (1 high)
High
NoOpStreamedSpan guard is dead code; get_traceparent will operate on no-op spans - `sentry_sdk/scope.py:587-589`
The condition was changed to use self.streamed_span for the not-None check, but the isinstance(self.span, NoOpStreamedSpan) check still references self.span. The self.span property returns None whenever self._span is a StreamedSpan (including NoOpStreamedSpan), because its getter filters by isinstance(self._span, Span). Since isinstance(None, NoOpStreamedSpan) is always False, the guard never short-circuits, so when a NoOpStreamedSpan is active the code falls through to self.streamed_span._to_traceparent() instead of using the propagation context. This produces incorrect traceparent headers for unsampled/no-op spans, breaking distributed tracing fidelity.
Also found at:
sentry_sdk/scope.py:605-607
Duration: 2m 31s · Tokens: 462.9k in / 7.6k out · Cost: $2.29 (+merge: $0.00)
Annotations
Check failure on line 589 in sentry_sdk/scope.py
sentry-warden / warden: code-review
NoOpStreamedSpan guard is dead code; get_traceparent will operate on no-op spans
The condition was changed to use `self.streamed_span` for the not-None check, but the `isinstance(self.span, NoOpStreamedSpan)` check still references `self.span`. The `self.span` property returns `None` whenever `self._span` is a `StreamedSpan` (including `NoOpStreamedSpan`), because its getter filters by `isinstance(self._span, Span)`. Since `isinstance(None, NoOpStreamedSpan)` is always False, the guard never short-circuits, so when a `NoOpStreamedSpan` is active the code falls through to `self.streamed_span._to_traceparent()` instead of using the propagation context. This produces incorrect traceparent headers for unsampled/no-op spans, breaking distributed tracing fidelity.
Check failure on line 607 in sentry_sdk/scope.py
sentry-warden / warden: code-review
[LWS-Z9X] NoOpStreamedSpan guard is dead code; get_traceparent will operate on no-op spans (additional location)
The condition was changed to use `self.streamed_span` for the not-None check, but the `isinstance(self.span, NoOpStreamedSpan)` check still references `self.span`. The `self.span` property returns `None` whenever `self._span` is a `StreamedSpan` (including `NoOpStreamedSpan`), because its getter filters by `isinstance(self._span, Span)`. Since `isinstance(None, NoOpStreamedSpan)` is always False, the guard never short-circuits, so when a `NoOpStreamedSpan` is active the code falls through to `self.streamed_span._to_traceparent()` instead of using the propagation context. This produces incorrect traceparent headers for unsampled/no-op spans, breaking distributed tracing fidelity.