-
Notifications
You must be signed in to change notification settings - Fork 557
Use float for sample rand #4677
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4677 +/- ##
==========================================
- Coverage 85.04% 84.97% -0.08%
==========================================
Files 156 156
Lines 15859 15851 -8
Branches 2684 2687 +3
==========================================
- Hits 13488 13469 -19
- Misses 1591 1597 +6
- Partials 780 785 +5
|
) | ||
sample_rand_scaled = rng.randrange(int(lower * 1000000), int(upper * 1000000)) | ||
|
||
return sample_rand_scaled / 1000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Sampling Context Propagation Fails for Tiny Rates
The _generate_sample_rand
function's integer scaling for randrange
arguments (int(value * 1e6)
) can cause the start
and stop
values to become equal for very narrow intervals (less than 1e-6). This leads randrange
to raise a ValueError
("empty range"). This error is caught in PropagationContext._fill_sample_rand
, which then silently skips setting the sample_rand
. As a result, dynamic sampling context propagation fails for traces with small sample_rate
s (e.g., when parent_sampled=True
with a tiny sample_rate
), leading to inconsistent sampling decisions across services.
Closes #4270