ref: Support outgoing trace propagation in span first (18) #5638
2 issues
code-review: Found 2 issues (1 high, 1 low)
High
NoOpStreamedSpan._iter_headers() raises AttributeError due to uninitialized _segment - `sentry_sdk/traces.py:504-512`
The new _iter_headers() method accesses self._segment but NoOpStreamedSpan does not initialize this attribute (it doesn't call super().__init__() and only sets _scope, _unsampled_reason, and _finished). In scope.py:688, span._iter_headers() is called without a guard against NoOpStreamedSpan, unlike _to_baggage() (line 607) and _get_trace_context() (line 621) which have not isinstance(self.span, NoOpStreamedSpan) checks. When iter_trace_propagation_headers() is called while a NoOpStreamedSpan is active, this will raise AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'.
Low
Inconsistent use of self._span vs self.span in get_trace_context - `sentry_sdk/scope.py:620-621`
In get_trace_context, line 620 checks self._span is not None but line 621 checks isinstance(self.span, NoOpStreamedSpan), mixing the private attribute with the public property. This is inconsistent with get_traceparent and get_baggage which consistently use self.span throughout. While currently functionally equivalent (since self.span just returns self._span), this inconsistency could cause subtle issues if the property behavior changes in the future.
Duration: 9m 35s · Tokens: 4.0M in / 44.9k out · Cost: $4.59 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.00)
Annotations
Check failure on line 512 in sentry_sdk/traces.py
sentry-warden / warden: code-review
NoOpStreamedSpan._iter_headers() raises AttributeError due to uninitialized _segment
The new `_iter_headers()` method accesses `self._segment` but `NoOpStreamedSpan` does not initialize this attribute (it doesn't call `super().__init__()` and only sets `_scope`, `_unsampled_reason`, and `_finished`). In `scope.py:688`, `span._iter_headers()` is called without a guard against `NoOpStreamedSpan`, unlike `_to_baggage()` (line 607) and `_get_trace_context()` (line 621) which have `not isinstance(self.span, NoOpStreamedSpan)` checks. When `iter_trace_propagation_headers()` is called while a `NoOpStreamedSpan` is active, this will raise `AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'`.