fix(metrics,logs): Don't attach span_id if no active span
#6162
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
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.