Sha256: b6943c79aee85d4aba50b00f084563080f0c59cb1b16d586ec4c96689acb2772

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

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

if !(%i[consistent_probability_based parent_consistent_probability_based] - OpenTelemetry::SDK::Trace::Samplers.singleton_methods).empty? &&
   !OpenTelemetry::SDK::Trace::Samplers.const_defined?(:ConsistentProbabilityTraceState) &&
   !OpenTelemetry::SDK::Trace::Samplers.const_defined?(:ParentConsistentProbabilityBased) &&
   !OpenTelemetry::SDK::Trace::Samplers.const_defined?(:ConsistentProbabilityBased)
  require 'opentelemetry/sdk/trace/samplers/consistent_probability_tracestate'
  require 'opentelemetry/sdk/trace/samplers/consistent_probability_based'
  require 'opentelemetry/sdk/trace/samplers/parent_consistent_probability_based'

  module OpenTelemetry
    module SDK
      module Experimental
        # The SamplersPatch module contains additional samplers for OpenTelemetry.
        module SamplersPatch
          # Returns a new sampler.
          #
          # @param [Numeric] ratio The desired sampling ratio.
          #   Must be within [0.0, 1.0].
          # @raise [ArgumentError] if ratio is out of range
          def consistent_probability_based(ratio)
            raise ArgumentError, 'ratio must be in range [0.0, 1.0]' unless (0.0..1.0).include?(ratio)

            OpenTelemetry::SDK::Trace::Samplers::ConsistentProbabilityBased.new(ratio)
          end

          # Returns a new sampler.
          #
          # @param [Sampler] root The sampler to which the sampling
          #   decision is delegated for spans with no parent (root spans).
          def parent_consistent_probability_based(root:)
            OpenTelemetry::SDK::Trace::Samplers::ParentConsistentProbabilityBased.new(root)
          end
        end
      end
    end
  end

  OpenTelemetry::SDK::Trace::Samplers.extend(OpenTelemetry::SDK::Experimental::SamplersPatch)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opentelemetry-sdk-experimental-0.3.2 lib/opentelemetry/sdk/experimental/samplers_patch.rb
opentelemetry-sdk-experimental-0.3.1 lib/opentelemetry/sdk/experimental/samplers_patch.rb
opentelemetry-sdk-experimental-0.3.0 lib/opentelemetry/sdk/experimental/samplers_patch.rb
opentelemetry-sdk-experimental-0.2.0 lib/opentelemetry/sdk/experimental/samplers_patch.rb
opentelemetry-sdk-experimental-0.1.1 lib/opentelemetry/sdk/experimental/samplers_patch.rb
opentelemetry-sdk-experimental-0.1.0 lib/opentelemetry/sdk/experimental/samplers_patch.rb