Class CollectorSampler


  • public abstract class CollectorSampler
    extends java.lang.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.

    • Constructor Detail

      • CollectorSampler

        protected CollectorSampler()
    • Method Detail

      • create

        public static CollectorSampler create​(float rate)
        Parameters:
        rate - minimum sample rate is 0.0001, or 0.01% of traces
      • boundary

        protected abstract long boundary()
      • isSampled

        public boolean isSampled​(java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object