Skip to content

Commit 9e4966b

Browse files
Computes cutoff/threshold once in DeterministicSampler. (#8395)
1 parent ea9e744 commit 9e4966b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

dd-trace-core/src/main/java/datadog/trace/common/sampling/DeterministicSampler.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ protected <T extends CoreSpan<T>> long getSamplingId(T span) {
3939
private static final double MAX = Math.pow(2, 64) - 1;
4040

4141
private final float rate;
42+
private final long threshold;
4243

4344
public DeterministicSampler(final double rate) {
4445
this.rate = (float) rate;
46+
this.threshold = cutoff(rate);
4547
}
4648

4749
@Override
4850
public <T extends CoreSpan<T>> boolean sample(final T span) {
49-
// unsigned 64 bit comparison with cutoff
50-
return getSamplingId(span) * KNUTH_FACTOR + Long.MIN_VALUE < cutoff(rate);
51+
// unsigned 64 bit comparison with cutoff/threshold
52+
return getSamplingId(span) * KNUTH_FACTOR + Long.MIN_VALUE < threshold;
5153
}
5254

5355
protected abstract <T extends CoreSpan<T>> long getSamplingId(T span);

0 commit comments

Comments
 (0)