Class: Sidekiq::Instrument::ServerMiddleware

Inherits:
Object
  • Object
show all
Includes:
MetricNames
Defined in:
lib/sidekiq/instrument/middleware/server.rb

Instance Method Summary collapse

Methods included from MetricNames

#max_retries, #metric_name, #worker_dog_options

Instance Method Details

#call(worker, job, _queue, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sidekiq/instrument/middleware/server.rb', line 10

def call(worker, job, _queue, &block)
  dequeue_string = is_retry(job) ? 'dequeue.retry' : 'dequeue'
  Statter.dogstatsd&.increment("sidekiq.#{dequeue_string}", worker_dog_options(worker, job))
  Statter.statsd.increment(metric_name(worker, dequeue_string))

  start_time = Time.now
  yield block
  execution_time_ms = (Time.now - start_time) * 1000
  Statter.dogstatsd&.timing('sidekiq.runtime', execution_time_ms, worker_dog_options(worker, job))
  Statter.statsd.measure(metric_name(worker, 'runtime'), execution_time_ms)
rescue Exception => e
  dd_options = worker_dog_options(worker, job)
  dd_options[:tags] << "error:#{e.class.name}"

  # if we have retries left, increment the enqueue.retry counter to indicate the job is going back on the queue
  if max_retries(worker) > current_retries(job) + 1
    WorkerMetrics.trace_workers_increment_counter(worker.class.to_s.underscore)
    Statter.dogstatsd&.increment('sidekiq.enqueue.retry', dd_options)
  end

  Statter.dogstatsd&.increment('sidekiq.error', dd_options)
  Statter.statsd.increment(metric_name(worker, 'error'))

  raise e
ensure
  WorkerMetrics.trace_workers_decrement_counter(worker.class.to_s.underscore)
  Statter.dogstatsd&.flush(sync: true)
end