ref: Add sampling to span first (11) #5617
3 issues
High
Uninitialized `_finished` attribute causes AttributeError on first call to `_end()` - `sentry_sdk/traces.py:485`
The _finished attribute is declared in __slots__ but never initialized in __init__. When _end() is called, the check if self._finished: on line 485 will raise an AttributeError because the attribute doesn't exist yet. This affects every NoOpStreamedSpan when it finishes, breaking span cleanup.
NoOpStreamedSpan created without scope will raise AttributeError on end() - `sentry_sdk/scope.py:1235`
When a child span is created from a NoOpStreamedSpan parent (line 1235), the new NoOpStreamedSpan is instantiated without the scope parameter. While this causes _start() to return early (since self._scope is None), the _finished attribute is never initialized in NoOpStreamedSpan.__init__(). When _end() is later called (e.g., via the context manager __exit__ or explicit end() call), it accesses self._finished before any assignment, causing an AttributeError: 'NoOpStreamedSpan' object has no attribute '_finished'.
Also found at:
sentry_sdk/traces.py:485-486
Medium
Baggage mutability check missing before modification - `sentry_sdk/scope.py:1254-1255`
The _update_sample_rate method modifies baggage.sentry_items["sample_rate"] without checking if the baggage is mutable. According to the Baggage class documentation, callers must check baggage.mutable is True before mutation. When a trace is continued from an incoming header containing sentry items, the baggage is immutable (mutable=False), so this modification violates the baggage contract and could lead to unexpected behavior in trace propagation.
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 2 | 1m 37s | $1.42 |
| find-bugs | 1 | 3m 45s | $2.79 |
| skill-scanner | 0 | 2m 10s | $0.42 |
| security-review | 0 | 3m 8s | $1.33 |
Duration: 10m 39s · Tokens: 3.9M in / 33.1k out · Cost: $5.98 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.01, +dedup: $0.00)