@Override public String toString() { return "CollectorSampler(" + boundary() + ")"; }
/** * Returns true if spans with this trace ID should be recorded to storage. * * <p>Zipkin v1 allows storage-layer sampling, which can help prevent spikes in traffic from * overloading the system. Debug spans are always stored. * * <p>This uses only the lower 64 bits of the trace ID as instrumentation still send mixed trace * ID width. * * @param hexTraceId the lower 64 bits of the span's trace ID are checked against the boundary * @param debug when true, always passes sampling */ public boolean isSampled(String hexTraceId, boolean debug) { if (Boolean.TRUE.equals(debug)) return true; long traceId = HexCodec.lowerHexToUnsignedLong(hexTraceId); // The absolute value of Long.MIN_VALUE is larger than a long, so Math.abs returns identity. // This converts to MAX_VALUE to avoid always dropping when traceId == Long.MIN_VALUE long t = traceId == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(traceId); return t <= boundary(); }