Skip to content

feat(tracing): Propagate sample_rand to transaction's baggage #4040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Feb 11, 2025

continue_trace now propagates incoming sample_rand values to the transaction's baggage. Also, in the case where sample_rand is missing from the incoming trace and needs to be backfilled, this change introduces a mechanism for the backfilled value from the scope's propagation context to be propagated to the transaction's baggage.

The transaction still does not use the sample_rand for making sampling decisions; this PR only enables propagation. A future PR will add support for reading the incoming/backfilled sample_rand and for using this value to make sampling decisions.

Depends on:

Ref #3998


Thank you for contributing to sentry-python! Please add tests to validate your changes, and lint your code using tox -e linters.

Running the test suite on your PR might require maintainer approval. The AWS Lambda tests additionally require a maintainer to add a special label, and they will fail until this label is added.

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.63%. Comparing base (789b065) to head (ccb969e).
Report is 4 commits behind head on szokeasaurusrex/sample_rand-2.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                        Coverage Diff                        @@
##           szokeasaurusrex/sample_rand-2    #4040      +/-   ##
=================================================================
+ Coverage                          79.56%   79.63%   +0.06%     
=================================================================
  Files                                140      140              
  Lines                              15561    15579      +18     
  Branches                            2639     2643       +4     
=================================================================
+ Hits                               12381    12406      +25     
+ Misses                              2343     2336       -7     
  Partials                             837      837              
Files with missing lines Coverage Δ
sentry_sdk/scope.py 85.57% <100.00%> (+0.03%) ⬆️
sentry_sdk/tracing.py 77.73% <100.00%> (+0.13%) ⬆️
sentry_sdk/tracing_utils.py 85.50% <100.00%> (+0.46%) ⬆️

... and 4 files with indirect coverage changes

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 14a70da to 0a0de06 Compare February 11, 2025 19:21
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 92cd6fb to bea45b9 Compare February 11, 2025 19:21
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 0a0de06 to 21bb038 Compare February 11, 2025 19:29
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from bea45b9 to 6363759 Compare February 11, 2025 19:30
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 21bb038 to 836d5b1 Compare February 11, 2025 19:39
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch 3 times, most recently from 154662a to af64b16 Compare February 12, 2025 08:41
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 836d5b1 to cbfc36a Compare February 12, 2025 11:43
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from af64b16 to 01334d7 Compare February 12, 2025 11:48
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from cbfc36a to 6f66ce8 Compare February 12, 2025 11:56
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 01334d7 to 7ec8e08 Compare February 12, 2025 11:57
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review February 12, 2025 12:18
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch 2 times, most recently from fec92c5 to d486a8f Compare February 13, 2025 15:38
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 7ec8e08 to b400fb1 Compare February 13, 2025 15:38
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch 2 times, most recently from 382ef64 to beb943b Compare February 18, 2025 15:22
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from b400fb1 to cf51e51 Compare February 18, 2025 15:22
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from beb943b to 93f41d6 Compare February 24, 2025 15:52
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from cf51e51 to 0db414f Compare February 24, 2025 15:58
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 93f41d6 to 5ffab05 Compare February 24, 2025 16:04
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 0db414f to 620b617 Compare February 24, 2025 16:04
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 5ffab05 to cb8e728 Compare February 24, 2025 16:18
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 620b617 to c8820e2 Compare February 24, 2025 16:20
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from c8820e2 to 64b4d84 Compare February 25, 2025 10:44
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from cb8e728 to 9863506 Compare February 25, 2025 10:49
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 64b4d84 to 6e56143 Compare February 25, 2025 10:50
@sentrivana
Copy link
Contributor

@szokeasaurusrex Were there relevant changes to this after Neel's last review? With the force pushes I can't tell.

@szokeasaurusrex
Copy link
Member Author

@szokeasaurusrex Were there relevant changes to this after Neel's last review? With the force pushes I can't tell.

Nope, just rebasing on #4038 and updating the tests in response to the changes in that PR

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch 2 times, most recently from 4add685 to c60cb71 Compare February 25, 2025 12:30
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.

lgtm

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from c60cb71 to 2b3f4f7 Compare February 25, 2025 14:31
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch 2 times, most recently from 11cfacd to f77a9ec Compare February 25, 2025 14:50
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-2 branch from 2b3f4f7 to 789b065 Compare February 25, 2025 14:53
`continue_trace` now propagates incoming `sample_rand` values to the transaction's baggage. Also, in the case where `sample_rand` is missing from the incoming trace and needs to be backfilled, this change introduces a mechanism for the backfilled value from the scope's propagation context to be propagated to the transaction's baggage.

The transaction still does not use the `sample_rand` for making sampling decisions; this PR only enables propagation. A future PR will add support for reading the incoming/backfilled `sample_rand` and for using this value to make sampling decisions.

Ref #3998
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from f77a9ec to 61ae6e7 Compare February 25, 2025 14:53
Use the `sample_rand` value from an incoming trace to make sampling
decisions, rather than generating a random value. When we are the head
SDK starting a new trace, save our randomly-generated value as the
`sample_rand`, and also change the random generation logic so that the
`sample_rand` is computed deterministically based on the `trace_id`.

Depends on:
  - #4040 
  - #4038 

Closes #3998
@sentrivana sentrivana merged commit 8cdcb70 into szokeasaurusrex/sample_rand-2 Feb 26, 2025
34 checks passed
@sentrivana sentrivana deleted the szokeasaurusrex/sample_rand-3 branch February 26, 2025 14:39
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.

3 participants