Skip to content

Merge branch 'master' into ivana/dont-attach-trace-id-if-not-known

0ea4cee
Select commit
Loading
Failed to load commit list.
Merged

fix(metrics,logs): Don't attach span_id if no active span #6162

Merge branch 'master' into ivana/dont-attach-trace-id-if-not-known
0ea4cee
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: code-review completed Apr 28, 2026 in 1m 0s

1 issue

code-review: Found 1 issue (1 medium)

Medium

apply_to_telemetry uses global current span instead of self's span - `sentry_sdk/scope.py:1855-1857`

The new code calls sentry_sdk.get_current_span() which internally invokes sentry_sdk.get_current_scope() rather than using self. The previous implementation derived span_id from self.get_trace_context(). If apply_to_telemetry is ever invoked on a scope other than the global current scope (e.g. an isolation/merged scope passed in by the client), the attached span_id will reflect the globally active span rather than the scope's own span. This is a subtle behavioral/side-effect change that may attach the wrong span_id to logs/metrics in nested or forked scope contexts.


Duration: 59.8s · Tokens: 190.7k in / 2.2k out · Cost: $0.53

Annotations

Check warning on line 1857 in sentry_sdk/scope.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

apply_to_telemetry uses global current span instead of self's span

The new code calls sentry_sdk.get_current_span() which internally invokes sentry_sdk.get_current_scope() rather than using self. The previous implementation derived span_id from self.get_trace_context(). If apply_to_telemetry is ever invoked on a scope other than the global current scope (e.g. an isolation/merged scope passed in by the client), the attached span_id will reflect the globally active span rather than the scope's own span. This is a subtle behavioral/side-effect change that may attach the wrong span_id to logs/metrics in nested or forked scope contexts.