Package brave.sampler

Class 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.

    • Method Detail

      • create

        public static Sampler create​(int tracesPerSecond)
      • isSampled

        public boolean isSampled​(long ignoredTraceId)
        Description copied from class: Sampler
        Returns true if the trace ID should be measured.
        Specified by:
        isSampled in class Sampler
        Parameters:
        ignoredTraceId - The trace ID to be decided on, can be ignored