Interface Sampler


public interface Sampler
Decides whether a new trace, or the proxy's part of a trace that came with the request, is sampled: recorded and exported. The samplers are OpenTelemetry's, by the names OTEL_TRACES_SAMPLER gives them: always_on, always_off, traceidratio and the parentbased_* ones, which follow a sampled flag that came with the request and ask their root sampler only for new traces.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Sampler
    Returns a sampler that samples nothing.
    static Sampler
    Returns a sampler that samples everything.
    Returns a description, such as ParentBased{root:TraceIdRatioBased{0.25}}.
    static Sampler
    of(String name, String arg)
    The sampler OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG name: always_on, always_off, traceidratio, parentbased_always_on (the default), parentbased_always_off or parentbased_traceidratio; the ratio is the argument, 1 when there is none.
    static Sampler
    A sampler that follows the request's sampled flag when it came with a trace context, and asks root otherwise.
    boolean
    shouldSample(SpanContext parent, long traceIdHigh, long traceIdLow)
    Decides.
    static Sampler
    traceIdRatio(double ratio)
    A sampler that samples a fraction of traces, decided by the trace id alone, so every process of a trace decides the same: the last 8 bytes of the id, as a signed number, are compared with ratio times Long.MAX_VALUE, as OpenTelemetry's Java SDK does.
  • Method Details

    • shouldSample

      boolean shouldSample(SpanContext parent, long traceIdHigh, long traceIdLow)
      Decides.
      Parameters:
      parent - the context that came with the request, or null for a new trace
      traceIdHigh - the trace id's first 8 bytes
      traceIdLow - the trace id's last 8 bytes, which traceIdRatio(double) decides by
      Returns:
      whether to sample
    • description

      String description()
      Returns a description, such as ParentBased{root:TraceIdRatioBased{0.25}}.
      Returns:
      a description, such as ParentBased{root:TraceIdRatioBased{0.25}}
    • alwaysOn

      static Sampler alwaysOn()
      Returns a sampler that samples everything.
      Returns:
      a sampler that samples everything
    • alwaysOff

      static Sampler alwaysOff()
      Returns a sampler that samples nothing.
      Returns:
      a sampler that samples nothing
    • traceIdRatio

      static Sampler traceIdRatio(double ratio)
      A sampler that samples a fraction of traces, decided by the trace id alone, so every process of a trace decides the same: the last 8 bytes of the id, as a signed number, are compared with ratio times Long.MAX_VALUE, as OpenTelemetry's Java SDK does.
      Parameters:
      ratio - the fraction, from 0 to 1
      Returns:
      the sampler
      Throws:
      IllegalArgumentException - if ratio is not in [0, 1]
    • parentBased

      static Sampler parentBased(Sampler root)
      A sampler that follows the request's sampled flag when it came with a trace context, and asks root otherwise.
      Parameters:
      root - the sampler of new traces
      Returns:
      the sampler
    • of

      static Sampler of(String name, String arg)
      The sampler OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG name: always_on, always_off, traceidratio, parentbased_always_on (the default), parentbased_always_off or parentbased_traceidratio; the ratio is the argument, 1 when there is none.
      Parameters:
      name - the sampler's name, or null for the default
      arg - the argument, or null
      Returns:
      the sampler
      Throws:
      IllegalArgumentException - for an unknown name or a bad ratio