ref: Support outgoing trace propagation in span first (18) #5638
3 issues
find-bugs: Found 3 issues (1 high, 1 medium, 1 low)
High
NoOpStreamedSpan missing _segment attribute causes AttributeError in inherited methods - `sentry_sdk/traces.py:504-512`
The new _iter_headers(), _to_baggage(), and _dynamic_sampling_context() methods access self._segment, but NoOpStreamedSpan.__init__() does not initialize this attribute. When these inherited methods are called on a NoOpStreamedSpan instance (e.g., through scope.iter_trace_propagation_headers() which doesn't guard against NoOpStreamedSpan), an AttributeError will be raised, crashing HTTP client integrations (stdlib, httpx, aiohttp, grpc, celery, etc.).
Also found at:
sentry_sdk/traces.py:492-502sentry_sdk/traces.py:514-529sentry_sdk/tracing_utils.py:1123-1124
Medium
Inconsistent handling of NoOpStreamedSpan between transaction setter and set_transaction_name - `sentry_sdk/scope.py:827-836`
The set_transaction_name method (lines 841-856) explicitly checks for NoOpStreamedSpan first and silently returns, then separately handles StreamedSpan. However, the transaction setter (lines 826-836) only checks for StreamedSpan without explicitly handling NoOpStreamedSpan first. Since NoOpStreamedSpan is a subclass of StreamedSpan, this causes NoOpStreamedSpan to trigger a deprecation warning in the setter, which is inconsistent with the silent handling in set_transaction_name. Users with NoOpStreamedSpan (unsampled traces) will see unexpected deprecation warnings.
Also found at:
sentry_sdk/scope.py:833
Low
Redundant Pattern import immediately overwritten - `sentry_sdk/tracing_utils.py:11`
Line 11 imports Pattern from typing, but this import is immediately overwritten by the try/except block at lines 15-19 which imports Pattern from re (Python 3.7+) or typing (Python 3.6 fallback). The import at line 11 serves no purpose since Python's module-level imports are executed sequentially and the later import overwrites it.
Duration: 13m 44s · Tokens: 7.2M in / 52.5k out · Cost: $10.27 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.00)
Annotations
Check failure on line 512 in sentry_sdk/traces.py
sentry-warden / warden: find-bugs
NoOpStreamedSpan missing _segment attribute causes AttributeError in inherited methods
The new `_iter_headers()`, `_to_baggage()`, and `_dynamic_sampling_context()` methods access `self._segment`, but `NoOpStreamedSpan.__init__()` does not initialize this attribute. When these inherited methods are called on a `NoOpStreamedSpan` instance (e.g., through `scope.iter_trace_propagation_headers()` which doesn't guard against `NoOpStreamedSpan`), an `AttributeError` will be raised, crashing HTTP client integrations (stdlib, httpx, aiohttp, grpc, celery, etc.).
Check failure on line 502 in sentry_sdk/traces.py
sentry-warden / warden: find-bugs
[J8H-STK] NoOpStreamedSpan missing _segment attribute causes AttributeError in inherited methods (additional location)
The new `_iter_headers()`, `_to_baggage()`, and `_dynamic_sampling_context()` methods access `self._segment`, but `NoOpStreamedSpan.__init__()` does not initialize this attribute. When these inherited methods are called on a `NoOpStreamedSpan` instance (e.g., through `scope.iter_trace_propagation_headers()` which doesn't guard against `NoOpStreamedSpan`), an `AttributeError` will be raised, crashing HTTP client integrations (stdlib, httpx, aiohttp, grpc, celery, etc.).
Check failure on line 529 in sentry_sdk/traces.py
sentry-warden / warden: find-bugs
[J8H-STK] NoOpStreamedSpan missing _segment attribute causes AttributeError in inherited methods (additional location)
The new `_iter_headers()`, `_to_baggage()`, and `_dynamic_sampling_context()` methods access `self._segment`, but `NoOpStreamedSpan.__init__()` does not initialize this attribute. When these inherited methods are called on a `NoOpStreamedSpan` instance (e.g., through `scope.iter_trace_propagation_headers()` which doesn't guard against `NoOpStreamedSpan`), an `AttributeError` will be raised, crashing HTTP client integrations (stdlib, httpx, aiohttp, grpc, celery, etc.).
Check failure on line 1124 in sentry_sdk/tracing_utils.py
sentry-warden / warden: find-bugs
[J8H-STK] NoOpStreamedSpan missing _segment attribute causes AttributeError in inherited methods (additional location)
The new `_iter_headers()`, `_to_baggage()`, and `_dynamic_sampling_context()` methods access `self._segment`, but `NoOpStreamedSpan.__init__()` does not initialize this attribute. When these inherited methods are called on a `NoOpStreamedSpan` instance (e.g., through `scope.iter_trace_propagation_headers()` which doesn't guard against `NoOpStreamedSpan`), an `AttributeError` will be raised, crashing HTTP client integrations (stdlib, httpx, aiohttp, grpc, celery, etc.).
Check warning on line 836 in sentry_sdk/scope.py
sentry-warden / warden: find-bugs
Inconsistent handling of NoOpStreamedSpan between transaction setter and set_transaction_name
The `set_transaction_name` method (lines 841-856) explicitly checks for `NoOpStreamedSpan` first and silently returns, then separately handles `StreamedSpan`. However, the `transaction` setter (lines 826-836) only checks for `StreamedSpan` without explicitly handling `NoOpStreamedSpan` first. Since `NoOpStreamedSpan` is a subclass of `StreamedSpan`, this causes `NoOpStreamedSpan` to trigger a deprecation warning in the setter, which is inconsistent with the silent handling in `set_transaction_name`. Users with `NoOpStreamedSpan` (unsampled traces) will see unexpected deprecation warnings.
Check warning on line 833 in sentry_sdk/scope.py
sentry-warden / warden: find-bugs
[656-MMN] Inconsistent handling of NoOpStreamedSpan between transaction setter and set_transaction_name (additional location)
The `set_transaction_name` method (lines 841-856) explicitly checks for `NoOpStreamedSpan` first and silently returns, then separately handles `StreamedSpan`. However, the `transaction` setter (lines 826-836) only checks for `StreamedSpan` without explicitly handling `NoOpStreamedSpan` first. Since `NoOpStreamedSpan` is a subclass of `StreamedSpan`, this causes `NoOpStreamedSpan` to trigger a deprecation warning in the setter, which is inconsistent with the silent handling in `set_transaction_name`. Users with `NoOpStreamedSpan` (unsampled traces) will see unexpected deprecation warnings.