Class: Sidekiq::Middleware::Client::Datadog

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/middleware/client/datadog.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Datadog

Configure and install datadog instrumentation. Example:

Sidekiq.configure_client do |config|
  config.client_middleware do |chain|
    chain.add Sidekiq::Middleware::Client::Datadog
  end
end

You might want to also call ‘client_middleware` in your `configure_server` call, since enqueued jobs can enqueue other jobs.

If you have other client middleware that can stop jobs from getting pushed, you might want to ensure this middleware is added last, to avoid reporting enqueues that later get stopped.

Options:

  • :hostname - the hostname used for instrumentation, defaults to system hostname, respects INSTRUMENTATION_HOSTNAME env variable

  • :metric_name - the metric name (prefix) to use, defaults to “sidekiq.job_enqueued”

  • :tags - array of custom tags, these can be plain strings or lambda blocks accepting a rack env instance

  • :skip_tags - array of tag names that shouldn’t be emitted

  • :statsd_host - the statsD host, defaults to “localhost”, respects STATSD_HOST env variable

  • :statsd_port - the statsD port, defaults to 8125, respects STATSD_PORT env variable

  • :statsd - custom statsd instance



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sidekiq/middleware/client/datadog.rb', line 34

def initialize(opts = {})
  statsd_host = opts[:statsd_host] || ENV['STATSD_HOST'] || 'localhost'
  statsd_port = (opts[:statsd_port] || ENV['STATSD_PORT'] || 8125).to_i

  @metric_name  = opts[:metric_name] || 'sidekiq.job_enqueued'
  @statsd       = opts[:statsd] || ::Datadog::Statsd.new(statsd_host, statsd_port)

  # `status` is meaningless when enqueueing
  skip_tags = Array(opts[:skip_tags]) + ['status']

  @tag_builder = Sidekiq::Datadog::TagBuilder.new(
    opts[:tags],
    skip_tags,
    opts[:hostname],
  )
end

Instance Method Details

#call(worker_class, job, queue, _redis_pool) ⇒ Object



51
52
53
54
# File 'lib/sidekiq/middleware/client/datadog.rb', line 51

def call(worker_class, job, queue, _redis_pool, *)
  record(worker_class, job, queue)
  yield
end