Class ParentBasedSampler

java.lang.Object
io.opentelemetry.sdk.trace.samplers.ParentBasedSampler
All Implemented Interfaces:
Sampler

@Immutable final class ParentBasedSampler extends Object implements Sampler
A Sampler that uses the sampled flag of the parent Span, if present. If the span has no parent, this Sampler will use the "root" sampler that it is built with. See documentation on the ParentBasedSamplerBuilder methods for the details on the various configurable options.
  • Field Details

    • root

      private final Sampler root
    • remoteParentSampled

      private final Sampler remoteParentSampled
    • remoteParentNotSampled

      private final Sampler remoteParentNotSampled
    • localParentSampled

      private final Sampler localParentSampled
    • localParentNotSampled

      private final Sampler localParentNotSampled
  • Constructor Details

  • Method Details

    • shouldSample

      public SamplingResult shouldSample(Context parentContext, String traceId, String name, SpanKind spanKind, Attributes attributes, List<LinkData> parentLinks)
      Description copied from interface: Sampler
      Called during Span creation to make a sampling samplingResult.
      Specified by:
      shouldSample in interface Sampler
      Parameters:
      parentContext - the parent span's SpanContext. This can be SpanContext.INVALID if this is a root span.
      traceId - the TraceId for the new Span. This will be identical to that in the parentContext, unless this is a root span.
      name - the name of the new Span.
      spanKind - the SpanKind of the Span.
      attributes - Attributes associated with the span.
      parentLinks - the parentLinks associated with the new Span.
      Returns:
      sampling samplingResult whether span should be sampled or not.
    • getDescription

      public String getDescription()
      Description copied from interface: Sampler
      Returns the description of this Sampler. This may be displayed on debug pages or in the logs.

      Example: "TraceIdRatioBased{0.000100}"

      Specified by:
      getDescription in interface Sampler
      Returns:
      the description of this Sampler.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object