Skip to content

Commit

Permalink
Fix sampling weight calculation (#6537)
Browse files Browse the repository at this point in the history
Using numeric casting, we always round down which leads to the sampling
weight being calculated less accurately. For example, a sample rate of
0.16666666666666666 results in a sampling weight of 5 instead of 6.
  • Loading branch information
davidtsuk authored Nov 7, 2024
1 parent 78c7a59 commit f8f3117
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rust_snuba/src/processors/eap_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl From<FromSpanMessage> for EAPSpan {

// lower precision to compensate floating point errors
res.sampling_factor = (res.sampling_factor * 1e9).round() / 1e9;
res.sampling_weight = (1.0 / res.sampling_factor) as u64;
res.sampling_weight = (1.0 / res.sampling_factor).round() as u64;

if let Some(data) = from.data {
for (k, v) in data {
Expand Down

0 comments on commit f8f3117

Please sign in to comment.