Skip to content

Commit 9b043e7

Browse files
committed
Normalize sample rates to 0..1
Avoiding bad knuth hash computation etc.
1 parent 217e1c7 commit 9b043e7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

ext/priority_sampling/priority_sampling.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ static void dd_decide_on_sampling(ddtrace_root_span_data *span) {
331331
sample_rate = result.sampling_rate;
332332
}
333333

334+
if (sample_rate > 1) {
335+
sample_rate = 1;
336+
} else if (sample_rate < 0) {
337+
sample_rate = 0;
338+
}
339+
334340
// this must be stable on re-evaluation
335341
bool sampling = (span->trace_id.low * KNUTH_FACTOR) <= (sample_rate * MAX_TRACE_ID);
336342
bool limited = false;

0 commit comments

Comments
 (0)