/** * 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); }
/** * 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); }