Skip to content
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

feat(tracing): Use sample_rand for sampling decisions #4044

Open
wants to merge 1 commit into
base: szokeasaurusrex/sample_rand-3
Choose a base branch
from

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Feb 12, 2025

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:

Closes #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 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.31%. Comparing base (7ec8e08) to head (5f57723).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                        Coverage Diff                        @@
##           szokeasaurusrex/sample_rand-3    #4044      +/-   ##
=================================================================
+ Coverage                          80.30%   80.31%   +0.01%     
=================================================================
  Files                                139      139              
  Lines                              15452    15462      +10     
  Branches                            2613     2615       +2     
=================================================================
+ Hits                               12409    12419      +10     
+ Misses                              2203     2202       -1     
- Partials                             840      841       +1     
Files with missing lines Coverage Δ
sentry_sdk/tracing.py 78.02% <100.00%> (+0.18%) ⬆️
sentry_sdk/tracing_utils.py 86.48% <100.00%> (+0.70%) ⬆️

... and 2 files with indirect coverage changes

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-4 branch from c3d6d12 to 5a906f6 Compare February 12, 2025 11:42
@szokeasaurusrex szokeasaurusrex marked this pull request as draft February 12, 2025 11:42
@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-4 branch from 5a906f6 to 548396d Compare February 12, 2025 11:51
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-3 branch from 01334d7 to 7ec8e08 Compare February 12, 2025 11:57
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-4 branch 4 times, most recently from c4abdc9 to 5f57723 Compare February 12, 2025 13:27
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review February 12, 2025 13:36
@szokeasaurusrex szokeasaurusrex linked an issue Feb 12, 2025 that may be closed by this pull request
Comment on lines +806 to +810
if baggage_sample_rand is not None:
self._sample_rand = baggage_sample_rand
else:
self._sample_rand = Random(self.trace_id).random()
Copy link
Contributor

Choose a reason for hiding this comment

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

In what cases will we have to generate a new _sample_rand here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whenever we are starting a new trace, i.e. if we call start_transaction without calling continue_trace first and without manually passing in baggage

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`.

Closes #3998
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sample_rand-4 branch from 5f57723 to b66c955 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
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.

Implement Sampling Seed Propagation
2 participants