Class: Jaeger::Samplers::PerOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/jaeger/samplers/per_operation.rb

Overview

A sampler that leverages both Probabilistic sampler and RateLimiting sampler via the GuaranteedThroughputProbabilistic sampler. This sampler keeps track of all operations and delegates calls the the respective GuaranteedThroughputProbabilistic sampler.

Constant Summary collapse

DEFAULT_SAMPLING_PROBABILITY =
0.001
DEFAULT_LOWER_BOUND =

sample once every 10 minutes’

1.0 / (10.0 * 60.0)

Instance Method Summary collapse

Constructor Details

#initialize(strategies:, max_operations:) ⇒ PerOperation

Returns a new instance of PerOperation.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jaeger/samplers/per_operation.rb', line 13

def initialize(strategies:, max_operations:)
  @max_operations = max_operations
  @default_sampling_probability =
    strategies[:default_sampling_probability] || DEFAULT_SAMPLING_PROBABILITY
  @lower_bound = strategies[:default_lower_bound_traces_per_second] || DEFAULT_LOWER_BOUND

  @default_sampler = Probabilistic.new(rate: @default_sampling_probability)
  @samplers = (strategies[:per_operation_strategies] || []).reduce({}) do |acc, strategy|
    operation = strategy.fetch(:operation)
    rate = strategy.fetch(:probabilistic_sampling)
    sampler = GuaranteedThroughputProbabilistic.new(
      lower_bound: @lower_bound,
      rate: rate
    )
    acc.merge(operation => sampler)
  end
end

Instance Method Details

#sample?(opts) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jaeger/samplers/per_operation.rb', line 31

def sample?(opts)
  operation_name = opts.fetch(:operation_name)
  sampler = @samplers[operation_name]
  return sampler.sample?(opts) if sampler

  return @default_sampler.sample?(opts) if @samplers.length >= @max_operations

  sampler = GuaranteedThroughputProbabilistic.new(
    lower_bound: @lower_bound,
    rate: @default_sampling_probability
  )
  @samplers[operation_name] = sampler
  sampler.sample?(opts)
end