Sha256: c03e001bfdbbb7997e85404f0bd241689d82e8c40c2b92134e8edcfdd74d19b3

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module SDK
    module Trace
      module Samplers
        # @api private
        #
        # This is a composite sampler. It either respects the parent span's sampling
        # decision or delegates to delegate_sampler for root spans.
        class ParentOrElse
          def initialize(delegate_sampler)
            @delegate_sampler = delegate_sampler
          end

          # @api private
          #
          # See {Samplers}.
          def description
            "ParentOrElse{#{@delegate_sampler.description}}"
          end

          # @api private
          #
          # See {Samplers}.
          def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
            if parent_context.nil?
              @delegate_sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
            elsif parent_context.trace_flags.sampled?
              RECORD_AND_SAMPLED
            else
              NOT_RECORD
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-sdk-0.5.1 lib/opentelemetry/sdk/trace/samplers/parent_or_else.rb
opentelemetry-sdk-0.5.0 lib/opentelemetry/sdk/trace/samplers/parent_or_else.rb