Sha256: 7efab9a436770ed48498bf8898703d2936f12220ef5ba958a780e3bd29939fb3

Contents?: true

Size: 833 Bytes

Versions: 3

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

module PrometheusExporter::Instrumentation
  class Sidekiq

    def initialize(client: nil)
      @client = client || PrometheusExporter::Client.default
    end

    def call(worker, msg, queue)
      success = false
      start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
      result = yield
      success = true
      result
    ensure
      duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
      class_name = if worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'
                     msg['wrapped']
                   else
                     worker.class.to_s
                   end

      @client.send_json(
        type: "sidekiq",
        name: class_name,
        success: success,
        duration: duration
      )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prometheus_exporter-0.4.2 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.1 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.0 lib/prometheus_exporter/instrumentation/sidekiq.rb