Class: Datadog::Tracing::Sampling::RateByKeySampler
- Defined in:
- lib/datadog/tracing/sampling/rate_by_key_sampler.rb
Overview
Samples at different rates by key.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_key ⇒ Object
readonly
Returns the value of attribute default_key.
Instance Method Summary collapse
- #default_sampler ⇒ Object
- #delete(key) ⇒ Object
- #delete_if(&block) ⇒ Object
-
#initialize(default_key, default_rate = 1.0, decision: nil, &block) ⇒ RateByKeySampler
constructor
A new instance of RateByKeySampler.
- #length ⇒ Object
- #resolve(trace) ⇒ Object
- #sample!(trace) ⇒ Object
- #sample_rate(trace) ⇒ Object
- #update(key, rate, decision: nil) ⇒ Object
- #update_all(rate_by_key, decision: nil) ⇒ Object
Constructor Details
#initialize(default_key, default_rate = 1.0, decision: nil, &block) ⇒ RateByKeySampler
Returns a new instance of RateByKeySampler.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 14 def initialize(default_key, default_rate = 1.0, decision: nil, &block) super() raise ArgumentError, 'No resolver given!' unless block @default_key = default_key @resolver = block @mutex = Mutex.new @samplers = {} set_rate(default_key, default_rate, decision) end |
Instance Attribute Details
#default_key ⇒ Object (readonly)
Returns the value of attribute default_key.
11 12 13 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 11 def default_key @default_key end |
Instance Method Details
#default_sampler ⇒ Object
31 32 33 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 31 def default_sampler @samplers[default_key] end |
#delete(key) ⇒ Object
63 64 65 66 67 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 63 def delete(key) @mutex.synchronize do @samplers.delete(key) end end |
#delete_if(&block) ⇒ Object
69 70 71 72 73 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 69 def delete_if(&block) @mutex.synchronize do @samplers.delete_if(&block) end end |
#length ⇒ Object
75 76 77 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 75 def length @samplers.length end |
#resolve(trace) ⇒ Object
27 28 29 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 27 def resolve(trace) @resolver.call(trace) end |
#sample!(trace) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 35 def sample!(trace) key = resolve(trace) @mutex.synchronize do @samplers.fetch(key, default_sampler).sample!(trace) end end |
#sample_rate(trace) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 43 def sample_rate(trace) key = resolve(trace) @mutex.synchronize do @samplers.fetch(key, default_sampler).sample_rate end end |
#update(key, rate, decision: nil) ⇒ Object
51 52 53 54 55 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 51 def update(key, rate, decision: nil) @mutex.synchronize do set_rate(key, rate, decision) end end |
#update_all(rate_by_key, decision: nil) ⇒ Object
57 58 59 60 61 |
# File 'lib/datadog/tracing/sampling/rate_by_key_sampler.rb', line 57 def update_all(rate_by_key, decision: nil) @mutex.synchronize do rate_by_key.each { |key, rate| set_rate(key, rate, decision) } end end |