-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
traceIDRatioSampler: use rightmost bits #3557
traceIDRatioSampler: use rightmost bits #3557
Conversation
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3557 +/- ##
=====================================
Coverage 78.0% 78.1%
=====================================
Files 164 164
Lines 11815 11815
=====================================
+ Hits 9226 9232 +6
+ Misses 2393 2387 -6
Partials 196 196
|
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.
👍🏻
I appreciate the reviews and merge, thanks! Would you also be able to share an estimate for when the next release will be cut? |
Before this PR:
The
traceIDRatioSampler
, when used with thexray.IDGenerator
, does not make random sampling decisions.In detail, the
xray.IDGenerator
generatestrace.TraceID
s such that the first 4 bytes represent a timestamp, with the remaining 12 bytes being randomly generated.The traceIDRatioSampler uses the first 8 bytes to make sampling decisions which means in practice any provided ratio ends up being effectively
0
or1.0
for any given point in time.Stated differently, for (nearly) any fixed point in time any provided ratio will be (effectivley ignored) and the sampler will consistently choose to either drop all traces or to record all traces, with no mix between.
After this PR:
The
traceIDRatioSampler
uses the last 8 bytes of thetrace.TraceID
, which lines up with the fully random portion of the ID generated byxray.IDGenerator
. Also brings the Go implementation into better alignment with its Python and Java equivalents (code references linked later).Demo
Check out https://go.dev/play/p/qpxm-boZuxj. Notably, at a sample rate of
0.25
, I getsampled 0/10000 (0.000000%)
but for a sample rate of0.5
, I getsampled 10000/10000 (100.000000%)
.Alternatives considered
The existing
traceIDRatioSampler
's implementation is correct under the assumption that the first values for 8 bytes are distributed uniformly randomly. With that in mind, we could consider this to be a bug with the ID generator for breaking this requirement, or just conclude the two are incompatible. In that direction, I think we'd expect thexray
package to provide a ratio sampler of its own, (and to call out clearly in documentation that it's incompatible with this package's ratio sampler).However,