Skip to content

Conversation

@sl0thentr0py
Copy link
Member

If we are on an external tracing system like otel, we allow registering a new source of trace_id/span_id that takes precedence over the scope's propagation_context.

  • Also reworked logs and metrics to use get_trace_context
  • Cleaned up handling of get_trace_context that is still messy but a bit more clearer now regarding which underlying propagation_context is used
@sl0thentr0py sl0thentr0py force-pushed the neel/external-prop-contex branch from 77c1d24 to 5c675fd Compare October 31, 2025 12:11
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 84.37500% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.91%. Comparing base (2397b15) to head (203d4d1).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/client.py 78.57% 0 Missing and 3 partials ⚠️
sentry_sdk/scope.py 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@ Coverage Diff @@ ## master #5051 +/- ## ========================================== - Coverage 83.93% 83.91% -0.03%  ========================================== Files 179 179 Lines 17887 17894 +7 Branches 3179 3177 -2 ========================================== + Hits 15013 15015 +2  - Misses 1906 1908 +2  - Partials 968 971 +3 
Files with missing lines Coverage Δ
sentry_sdk/scope.py 88.65% <88.88%> (+0.16%) ⬆️
sentry_sdk/client.py 83.65% <78.57%> (-0.13%) ⬇️

... and 3 files with indirect coverage changes

@sl0thentr0py sl0thentr0py force-pushed the neel/external-prop-contex branch 4 times, most recently from e902c81 to 3763d47 Compare October 31, 2025 12:37
If we are on an external tracing system like otel, we allow registering a new source of `trace_id/span_id` that takes precedence over the scope's propagation_context. * Also reworked logs and metrics to use `get_trace_context` * Cleaned up handling of `get_trace_context` that is still messy but a bit more clearer now regarding which underlying `propagation_context` is used
@sl0thentr0py sl0thentr0py force-pushed the neel/external-prop-contex branch from 3763d47 to 203d4d1 Compare October 31, 2025 12:55

# Add "trace" context
if contexts.get("trace") is None:
if has_tracing_enabled(options) and self._span is not None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved these into get_trace_context for consistency


return trace_context
propagation_context = self.get_active_propagation_context()
if propagation_context is None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propagation_context is actually never None, but this implementation is whack so we need this redundant check...

Copy link
Member Author

@sl0thentr0py sl0thentr0py Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some future cleanup, if you see get_active_propagation_context that's also really shady. I generally dislike that so many instance methods on this scope call and fetch other scopes themselves, it's entirely spaghetti but somehow works in the common code paths.

@sl0thentr0py sl0thentr0py marked this pull request as ready for review October 31, 2025 13:05
@sl0thentr0py sl0thentr0py requested a review from a team as a code owner October 31, 2025 13:05
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good as far as I can tell. Thanks for centralizing the logic more, def an improvement to directly accessing the propagation context from random places 😢

@sl0thentr0py sl0thentr0py merged commit 8965821 into master Oct 31, 2025
130 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/external-prop-contex branch October 31, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants