Sha256: fb5c4d5e5063a96da844bc5f0d7fbeb11f9980ce05d99ac2fd9d43e4372d53ef

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Jaeger
  module Samplers
    # Samples at most max_traces_per_second. The distribution of sampled
    # traces follows burstiness of the service, i.e. a service with uniformly
    # distributed requests will have those requests sampled uniformly as
    # well, but if requests are bursty, especially sub-second, then a number
    # of sequential requests can be sampled each second.
    class RateLimiting
      attr_reader :tags

      def initialize(max_traces_per_second: 10)
        if max_traces_per_second < 0.0
          raise "max_traces_per_second must not be negative, got #{max_traces_per_second}"
        end

        @rate_limiter = RateLimiter.new(
          credits_per_second: max_traces_per_second,
          max_balance: [max_traces_per_second, 1.0].max
        )
        @tags = {
          'sampler.type' => 'ratelimiting',
          'sampler.param' => max_traces_per_second
        }
      end

      def sample?(*)
        [@rate_limiter.check_credit(1.0), @tags]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jaeger-client-0.10.0 lib/jaeger/samplers/rate_limiting.rb