/** * @param rate 0 means never sample, 1 means always sample. Otherwise minimum sample rate is 0.01, * or 1% of traces */ public static Sampler create(final float rate) { if (rate == 0) return NEVER_SAMPLE; if (rate == 1.0) return ALWAYS_SAMPLE; if (rate < 0.01f || rate > 1) { throw new IllegalArgumentException("rate should be between 0.01 and 1: was " + rate); } return new CountingSampler(rate); }
/** * Returns a sampler, given a rate expressed as a percentage. * * <p>The sampler returned is good for low volumes of traffic (<100K requests), as it is precise. * If you have high volumes of traffic, consider {@link BoundarySampler}. * * @param rate minimum sample rate is 0.01, or 1% of traces */ public static Sampler create(float rate) { return CountingSampler.create(rate); } }
/** loops over the pre-canned decisions, resetting to zero when it gets to the end. */ @Override public boolean isSampled(long traceIdIgnored) { return sampleDecisions.get(mod(counter.getAndIncrement(), 100)); }
/** * Fills a bitset with decisions according to the supplied rate with the supplied {@link Random}. */ CountingSampler(float rate, Random random) { counter = new AtomicInteger(); int outOf100 = (int) (rate * 100.0f); this.sampleDecisions = randomBitSet(100, outOf100, random); }
/** * Fills a bitset with decisions according to the supplied rate with the supplied {@link Random}. */ CountingSampler(float rate, Random random) { counter = new AtomicInteger(); int outOf100 = (int) (rate * 100.0f); this.sampleDecisions = randomBitSet(100, outOf100, random); }
/** * @param rate percentage of requests to start traces for. 1.0 is 100% */ protected Rule(float rate) { sampler = CountingSampler.create(rate); }
/** * @param rate 0 means never sample, 1 means always sample. Otherwise minimum sample rate is 0.01, * or 1% of traces */ public static Sampler create(final float rate) { if (rate == 0) return NEVER_SAMPLE; if (rate == 1.0) return ALWAYS_SAMPLE; if (rate < 0.01f || rate > 1) { throw new IllegalArgumentException("rate should be between 0.01 and 1: was " + rate); } return new CountingSampler(rate); }
/** loops over the pre-canned decisions, resetting to zero when it gets to the end. */ @Override public boolean isSampled(long traceIdIgnored) { return sampleDecisions.get(mod(counter.getAndIncrement(), 100)); }
public SamplingFlags sample(@Nullable M method) { if (method == null) return SamplingFlags.EMPTY; Sampler sampler = methodsToSamplers.get(method); if (sampler == NULL_SENTINEL) return SamplingFlags.EMPTY; if (sampler != null) return sample(sampler); Float rate = rateForMethod.get(method); if (rate == null) { methodsToSamplers.put(method, NULL_SENTINEL); return SamplingFlags.EMPTY; } sampler = CountingSampler.create(rate); Sampler previousSampler = methodsToSamplers.putIfAbsent(method, sampler); if (previousSampler != null) sampler = previousSampler; // lost race, use the existing counter return sample(sampler); }
/** * Returns a sampler, given a rate expressed as a percentage. * * <p>The sampler returned is good for low volumes of traffic (<100K requests), as it is precise. * If you have high volumes of traffic, consider {@link BoundarySampler}. * * @param rate minimum sample rate is 0.01, or 1% of traces */ public static Sampler create(float rate) { return CountingSampler.create(rate); } }
/** * @param rate percentage of requests to start traces for. 1.0 is 100% */ protected Rule(float rate) { sampler = CountingSampler.create(rate); }
public SamplingFlags sample(@Nullable M method) { if (method == null) return SamplingFlags.EMPTY; Sampler sampler = methodsToSamplers.get(method); if (sampler == NULL_SENTINEL) return SamplingFlags.EMPTY; if (sampler != null) return sample(sampler); Float rate = rateForMethod.get(method); if (rate == null) { methodsToSamplers.put(method, NULL_SENTINEL); return SamplingFlags.EMPTY; } sampler = CountingSampler.create(rate); Sampler previousSampler = methodsToSamplers.putIfAbsent(method, sampler); if (previousSampler != null) sampler = previousSampler; // lost race, use the existing counter return sample(sampler); }