fix(metrics,logs): Don't attach span_id if no active span
#6162
1 issue
Medium
else branch overwrites a pre-existing telemetry['span_id'] with external propagation context - `sentry_sdk/scope.py:1855-1866`
The original code only set telemetry['span_id'] when telemetry.get('span_id') is None. In the new structure, the else branch runs whenever the if-condition fails for any reason — including the case where telemetry['span_id'] is already populated by the caller. In that else branch, if an external propagation context exists, it unconditionally overwrites the already-set telemetry['span_id']. This is a behavioral regression: any caller that pre-populated span_id on the telemetry payload (e.g. logs/metrics constructed with an explicit span_id) will have it silently replaced when external (e.g. OTel) propagation is registered, leading to incorrect span_id values reported to Sentry.
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 0 | 23.0s | $0.47 |
| find-bugs | 1 | 40.6s | $0.68 |
| skill-scanner | 0 | 34.3s | $0.20 |
| security-review | 0 | 39.9s | $0.22 |
Duration: 2m 18s · Tokens: 484.7k in / 3.4k out · Cost: $1.58 (+extraction: $0.00, +dedup: $0.01)