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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategies:, max_operations:) ⇒ PerOperation

Returns a new instance of PerOperation.



15
16
17
18
19
# File 'lib/jaeger/samplers/per_operation.rb', line 15

def initialize(strategies:, max_operations:)
  @max_operations = max_operations
  @samplers = {}
  update(strategies: strategies)
end

Instance Attribute Details

#default_sampling_probabilityObject (readonly)

Returns the value of attribute default_sampling_probability.



13
14
15
# File 'lib/jaeger/samplers/per_operation.rb', line 13

def default_sampling_probability
  @default_sampling_probability
end

#lower_boundObject (readonly)

Returns the value of attribute lower_bound.



13
14
15
# File 'lib/jaeger/samplers/per_operation.rb', line 13

def lower_bound
  @lower_bound
end

#samplersObject (readonly)

Returns the value of attribute samplers.



13
14
15
# File 'lib/jaeger/samplers/per_operation.rb', line 13

def samplers
  @samplers
end

Instance Method Details

#sample(opts) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jaeger/samplers/per_operation.rb', line 38

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

#update(strategies:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jaeger/samplers/per_operation.rb', line 21

def update(strategies:)
  is_updated = false

  @default_sampling_probability =
    strategies[:default_sampling_probability] || DEFAULT_SAMPLING_PROBABILITY
  @lower_bound =
    strategies[:default_lower_bound_traces_per_second] || DEFAULT_LOWER_BOUND

  if @default_sampler
    is_updated = @default_sampler.update(rate: @default_sampling_probability)
  else
    @default_sampler = Probabilistic.new(rate: @default_sampling_probability)
  end

  update_operation_strategies(strategies) || is_updated
end