Skip to content

Conversation

@sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Dec 10, 2025

Description

  • Add get_baggage, get_traceparent and iter_headers to PropagationContext so that the contract is similar to Span.
    • This clarifies that the PropagationContext and Span are themselves responsible for constructing these values and not the Scope.
    • Currently, it is all a mess on Scope which does not clarify state responsibilities correctly on who holds and can populate what.
  • Add Baggage.populate_from_propagation_context as a replacement for Baggage.from_options (that took a scope argument).
  • Unify all the various propagation_context presence checks in Scope methods to get_active_propagation_context.
    • This get_active_propagation_context logic then remains the central problem to fix in the future.

Deprecations

The following methods are thus no longer used internally and deprecated.

  • Scope.get_dynamic_sampling_context
  • Scope.iter_headers
  • Baggage.from_options

@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.23%. Comparing base (2ce4379) to head (1ac88a0).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/scope.py 57.14% 3 Missing and 3 partials ⚠️
sentry_sdk/tracing_utils.py 84.21% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5215      +/-   ##
==========================================
- Coverage   84.25%   84.23%   -0.02%     
==========================================
  Files         181      181              
  Lines       18463    18458       -5     
  Branches     3288     3282       -6     
==========================================
- Hits        15556    15549       -7     
- Misses       1894     1902       +8     
+ Partials     1013     1007       -6     
Files with missing lines Coverage Δ
sentry_sdk/tracing_utils.py 86.79% <84.21%> (-0.03%) ⬇️
sentry_sdk/scope.py 88.06% <57.14%> (-0.31%) ⬇️

@sl0thentr0py sl0thentr0py force-pushed the neel/more-prop-context-cleanup branch 8 times, most recently from e480bc1 to 9c8bfff Compare December 10, 2025 18:07

# Fall back to isolation scope's traceparent. It always has one
return self.get_isolation_scope().get_traceparent()
# TODO-neel will never happen
Copy link
Member Author

@sl0thentr0py sl0thentr0py Dec 10, 2025

Choose a reason for hiding this comment

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

follow up PR
#5217

@sl0thentr0py sl0thentr0py marked this pull request as ready for review December 10, 2025 19:10
@sl0thentr0py sl0thentr0py requested a review from a team as a code owner December 10, 2025 19:10
@sl0thentr0py sl0thentr0py force-pushed the neel/more-prop-context-cleanup branch from 9c8bfff to 1ac88a0 Compare December 10, 2025 19:24
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.

Two small comments re naming for now, will still review properly, need to understand the new flow

# type: () -> str
return f"{self.trace_id}-{self.span_id}"

def get_baggage(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same nit as above

Suggested change
def get_baggage(self):
def to_baggage(self):

Copy link
Member Author

@sl0thentr0py sl0thentr0py Dec 11, 2025

Choose a reason for hiding this comment

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

we actually don't use Span.to_baggage anywhere and the Span.iter_headers uses get_baggage from the transaction itself so I'll leave this as get_baggage.

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.

Much, much better already, thank you!

@sl0thentr0py sl0thentr0py force-pushed the neel/more-prop-context-cleanup branch from 1ac88a0 to d5b454a Compare December 11, 2025 13:14
@sl0thentr0py sl0thentr0py force-pushed the neel/more-prop-context-cleanup branch from d5b454a to 598e594 Compare December 11, 2025 13:18
@sl0thentr0py sl0thentr0py enabled auto-merge (squash) December 11, 2025 13:22
@sl0thentr0py sl0thentr0py merged commit d662111 into master Dec 11, 2025
153 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/more-prop-context-cleanup branch December 11, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants