Class ParentBasedSampler

  • All Implemented Interfaces:
    Sampler

    @Immutable
    public 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 ParentBasedSampler.Builder methods for the details on the various configurable options.
    • Method Detail

      • shouldSample

        public SamplingResult shouldSample​(io.opentelemetry.context.Context parentContext,
                                           String traceId,
                                           String name,
                                           io.opentelemetry.api.trace.Span.Kind spanKind,
                                           io.opentelemetry.api.common.Attributes attributes,
                                           List<SpanData.Link> 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 Span.Kind 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object