Skip to content

ref: Add sampling to span first (11) #1548

ref: Add sampling to span first (11)

ref: Add sampling to span first (11) #1548

Triggered via pull request March 10, 2026 12:02
@sentrivanasentrivana
synchronize #5617
Status Success
Total duration 20s
Artifacts

changelog-preview.yml

on: pull_request_target
changelog-preview  /  preview
15s
changelog-preview / preview
Fit to window
Zoom out
Zoom in

Annotations

3 errors and 1 warning
Uninitialized `_finished` attribute causes AttributeError on first call to `_end()`: sentry_sdk/traces.py#L485
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#L1235
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'`.
[VMY-PE3] NoOpStreamedSpan created without scope will raise AttributeError on end() (additional location): sentry_sdk/traces.py#L485
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'`.
Baggage mutability check missing before modification: sentry_sdk/scope.py#L1254
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.