66package io .opentelemetry .contrib .sampler .consistent56 ;
77
88import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .calculateSamplingProbability ;
9+ import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .calculateThreshold ;
910import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .checkThreshold ;
1011import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .getInvalidThreshold ;
1112import static io .opentelemetry .contrib .sampler .consistent56 .ConsistentSamplingUtil .getMaxThreshold ;
@@ -22,9 +23,20 @@ public class ConsistentFixedThresholdSampler extends ConsistentSampler {
2223 private final String description ;
2324
2425 protected ConsistentFixedThresholdSampler (long threshold ) {
26+ this .threshold = getThreshold (threshold );
27+ this .description = getThresholdDescription (threshold );
28+ }
29+
30+ protected ConsistentFixedThresholdSampler (double samplingProbability ) {
31+ this (calculateThreshold (samplingProbability ));
32+ }
33+
34+ private static long getThreshold (long threshold ) {
2535 checkThreshold (threshold );
26- this .threshold = threshold ;
36+ return threshold ;
37+ }
2738
39+ private static String getThresholdDescription (long threshold ) {
2840 String thresholdString ;
2941 if (threshold == getMaxThreshold ()) {
3042 thresholdString = "max" ;
@@ -35,12 +47,11 @@ protected ConsistentFixedThresholdSampler(long threshold) {
3547 .toString ();
3648 }
3749
38- this .description =
39- "ConsistentFixedThresholdSampler{threshold="
40- + thresholdString
41- + ", sampling probability="
42- + calculateSamplingProbability (threshold )
43- + "}" ;
50+ return "ConsistentFixedThresholdSampler{threshold="
51+ + thresholdString
52+ + ", sampling probability="
53+ + calculateSamplingProbability (threshold )
54+ + "}" ;
4455 }
4556
4657 @ Override
0 commit comments