Skip to content

.

8aca36a
Select commit
Loading
Failed to load commit list.
Open

feat(span-first): Support before_send_span #6239

.
8aca36a
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed May 11, 2026 in 4m 38s

3 issues

find-bugs: Found 3 issues (2 medium, 1 low)

Medium

before_send_span return missing 'attributes' silently wipes all span attributes - `sentry_sdk/client.py:982-984`

At line 982 the code unconditionally resets telemetry._attributes = {} before re-populating from serialized.get('attributes') or {}. If a user's before_send_span returns a dict that contains 'name' but omits the 'attributes' key (a natural pattern when the user only intends to modify the name), every attribute on the span is silently dropped. This is data loss that contradicts the PR's design intent of letting users 'modify specific parts' of the span.

User-supplied before_send_span exception propagates out of _capture_telemetry - `sentry_sdk/client.py:967-968`

The before_send call at line 968 is not wrapped in capture_internal_exceptions(), unlike before_send/before_send_transaction at client.py:676-677 and 702-703. A user-supplied before_send_span (or before_send_log/metric) that raises will propagate out of _capture_telemetry, disrupting the span end path that called _capture_span. This can crash user code during ordinary span finalization.

Low

_segment_span reference in serialized dict retains StreamedSpan object - `sentry_sdk/client.py:1000-1004`

Line 1003 stores telemetry._segment (a StreamedSpan instance) onto the serialized dict before queueing it in the batcher. The PR description states that queuing dictionaries instead of StreamedSpan instances should decrease memory footprint, but every queued span still holds a strong reference to its segment span StreamedSpan (and transitively its scope, baggage, attributes), undermining that goal and potentially keeping long-lived segments alive until all their children flush.


⏱ 2m 9s · 713.6k in / 8.5k out · $4.25 (+verification: $3.20, +merge: $0.00)

Annotations

Check warning on line 984 in sentry_sdk/client.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

before_send_span return missing 'attributes' silently wipes all span attributes

At line 982 the code unconditionally resets telemetry._attributes = {} before re-populating from serialized.get('attributes') or {}. If a user's before_send_span returns a dict that contains 'name' but omits the 'attributes' key (a natural pattern when the user only intends to modify the name), every attribute on the span is silently dropped. This is data loss that contradicts the PR's design intent of letting users 'modify specific parts' of the span.

Check warning on line 968 in sentry_sdk/client.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

User-supplied before_send_span exception propagates out of _capture_telemetry

The before_send call at line 968 is not wrapped in capture_internal_exceptions(), unlike before_send/before_send_transaction at client.py:676-677 and 702-703. A user-supplied before_send_span (or before_send_log/metric) that raises will propagate out of _capture_telemetry, disrupting the span end path that called _capture_span. This can crash user code during ordinary span finalization.