Class ParentBasedSampler

  • All Implemented Interfaces:
    Sampler

    @Immutable
    final class ParentBasedSampler
    extends java.lang.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 Detail

      • remoteParentSampled

        private final Sampler remoteParentSampled
      • remoteParentNotSampled

        private final Sampler remoteParentNotSampled
      • localParentSampled

        private final Sampler localParentSampled
      • localParentNotSampled

        private final Sampler localParentNotSampled
    • Constructor Detail

      • ParentBasedSampler

        ParentBasedSampler​(Sampler root,
                           @Nullable
                           Sampler remoteParentSampled,
                           @Nullable
                           Sampler remoteParentNotSampled,
                           @Nullable
                           Sampler localParentSampled,
                           @Nullable
                           Sampler localParentNotSampled)
    • Method Detail

      • shouldSample

        public SamplingResult shouldSample​(Context parentContext,
                                           java.lang.String traceId,
                                           java.lang.String name,
                                           SpanKind spanKind,
                                           Attributes attributes,
                                           java.util.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 java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object