Sha256: 8bfbd305382189315ef80c208c20ed4fa464741d8149656c23913d49a2dbd00e

Contents?: true

Size: 896 Bytes

Versions: 4

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

module Jaeger
  module Samplers
    # Probabilistic sampler
    #
    # Sample a portion of traces using trace_id as the random decision
    class Probabilistic
      attr_reader :rate

      def initialize(rate: 0.001)
        update(rate: rate)
      end

      def update(rate:)
        if rate < 0.0 || rate > 1.0
          raise "Sampling rate must be between 0.0 and 1.0, got #{rate.inspect}"
        end

        new_boundary = TraceId::TRACE_ID_UPPER_BOUND * rate
        return false if @boundary == new_boundary

        @rate = rate
        @boundary = TraceId::TRACE_ID_UPPER_BOUND * rate
        @tags = {
          'sampler.type' => 'probabilistic',
          'sampler.param' => rate
        }

        true
      end

      def sample(opts)
        trace_id = opts.fetch(:trace_id)

        [@boundary >= trace_id, @tags]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
dox-jaeger-client-2.0.0 lib/jaeger/samplers/probabilistic.rb
jaeger-client-with-ruby-32-support-2.0.0 lib/jaeger/samplers/probabilistic.rb
jaeger-client-1.3.0 lib/jaeger/samplers/probabilistic.rb
jaeger-client-1.2.0 lib/jaeger/samplers/probabilistic.rb