feat(span-first): Support before_send_span
#6239
Open
@sentry/warden / warden
completed
May 11, 2026 in 4m 58s
1 issue
Medium
_estimate_size raises KeyError when span lacks attributes - `sentry_sdk/_span_batcher.py:151`
_estimate_size accesses item["attributes"].values() unconditionally, but 'attributes' is NotRequired in SpanJSON. The new before_send_span feature allows users to return a modified dict. While the intent is that invalid returns should fall back to the original span, the validation at client.py:979 only checks isinstance(serialized, dict) and serialized (non-empty). This allows dicts like {"not_a_span": True} to pass validation. When such a dict reaches _span_batcher.add(), it will raise KeyError in _estimate_size at line 151, causing the span to be dropped and potentially propagating the exception.
Also found at:
sentry_sdk/_span_batcher.py:165-170sentry_sdk/client.py:978-986
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| security-review | 0 | 57.2s | $0.24 |
| code-review | 0 | 1m 12s | $0.25 |
| find-bugs | 1 | 1m 17s | $4.48 |
| skill-scanner | 0 | 42.0s | $0.29 |
⏱ 4m 8s · 1.3M in / 10.3k out · $5.26 (+verification: $3.35, +merge: $0.00)
Loading