Class CollectorSampler

java.lang.Object
zipkin2.collector.CollectorSampler

public abstract class CollectorSampler extends Object
CollectorSampler decides if a particular trace should be "sampled", i.e. recorded in permanent storage. This involves a consistent decision based on the span's trace ID with one notable exception: Debug spans are always stored.

Implementation

Accepts a percentage of trace ids by comparing their absolute value against a potentially dynamic boundary. eg isSampled == abs(traceId) <= boundary

While idempotent, this implementation's sample rate won't exactly match the input rate because trace ids are not perfectly distributed across 64bits. For example, tests have shown an error rate of 3% when 100K trace ids are random.

  • Field Details

  • Constructor Details

    • CollectorSampler

      protected CollectorSampler()
  • Method Details

    • create

      public static CollectorSampler create(float rate)
      Returns a trace ID sampler with the indicated rate.
      Parameters:
      rate - minimum sample rate is 0.0001, or 0.01% of traces
    • boundary

      protected abstract long boundary()
    • isSampled

      public boolean isSampled(String hexTraceId, boolean debug)
      Returns true if spans with this trace ID should be recorded to storage.

      Zipkin v1 allows storage-layer sampling, which can help prevent spikes in traffic from overloading the system. Debug spans are always stored.

      This uses only the lower 64 bits of the trace ID as instrumentation still send mixed trace ID width.

      Parameters:
      hexTraceId - the lower 64 bits of the span's trace ID are checked against the boundary
      debug - when true, always passes sampling
    • toString

      public String toString()
      Overrides:
      toString in class Object