# 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