Class: Datadog::RateByServiceSampler

Inherits:
RateByKeySampler show all
Defined in:
lib/ddtrace/sampler.rb

Overview

RateByServiceSampler samples different services at different rates

Constant Summary collapse

DEFAULT_KEY =
'service:,env:'.freeze

Instance Attribute Summary

Attributes inherited from RateByKeySampler

#default_key

Instance Method Summary collapse

Methods inherited from RateByKeySampler

#default_sampler, #delete, #delete_if, #length, #resolve, #sample!, #sample?, #sample_rate, #update_all

Methods inherited from Sampler

#sample!, #sample?, #sample_rate

Constructor Details

#initialize(default_rate = 1.0, options = {}) ⇒ RateByServiceSampler

Returns a new instance of RateByServiceSampler.



166
167
168
169
# File 'lib/ddtrace/sampler.rb', line 166

def initialize(default_rate = 1.0, options = {})
  super(DEFAULT_KEY, default_rate, &method(:key_for))
  @env = options[:env]
end

Instance Method Details

#update(rate_by_service) ⇒ Object



171
172
173
174
175
176
177
178
179
180
# File 'lib/ddtrace/sampler.rb', line 171

def update(rate_by_service)
  # Remove any old services
  delete_if { |key, _| key != DEFAULT_KEY && !rate_by_service.key?(key) }

  # Update each service rate
  update_all(rate_by_service)

  # Emit metric for service cache size
  Diagnostics::Health.metrics.sampling_service_cache_length(length)
end