Class RateLimitingSampler
- java.lang.Object
-
- brave.sampler.Sampler
-
- brave.sampler.RateLimitingSampler
-
public class RateLimitingSampler extends Sampler
The rate-limited sampler allows you to choose an amount of traces to accept on a per-second interval. The minimum number is 0 and the max is 2,147,483,647 (max int).For example, to allow 10 traces per second, you'd initialize the following:
tracingBuilder.sampler(RateLimitingSampler.create(10));
Appropriate Usage
If the rate is 10 or more traces per second, an attempt is made to distribute the accept decisions equally across the second. For example, if the rate is 100, 10 will pass every decisecond as opposed to bunching all pass decisions at the beginning of the second.
This sampler is efficient, but not as efficient as the
BoundarySampler
. However, this sampler is insensitive to the trace ID and will operate correctly even if they are not perfectly random.Implementation
The implementation uses
System.nanoTime()
and tracks how many yes decisions occur across a second window. When the rate is at least 10/s, the yes decisions are equally split over 10 deciseconds, allowing a roll-over of unused yes decisions up until the end of the second.
-
-
Field Summary
-
Fields inherited from class brave.sampler.Sampler
ALWAYS_SAMPLE, NEVER_SAMPLE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Sampler
create(int tracesPerSecond)
boolean
isSampled(long ignoredTraceId)
Returns true if the trace ID should be measured.
-
-
-
Method Detail
-
create
public static Sampler create(int tracesPerSecond)
-
-