class Sidekiq::Ichnite::ServerMiddleware

Public Instance Methods

call(worker, msg, queue) { || ... } click to toggle source
# File lib/sidekiq-ichnite/middleware.rb, line 54
def call(worker, msg, queue)
  ::Ichnite.enter(
    job_id: Sidekiq::Ichnite.job_id(msg),
    job_class: Sidekiq::Ichnite.job_class(msg)) do
    begin
      context = { queue: queue }

      ts = Time.now.to_f
      # We are currently not logging start events.
      # This would most likely blow our SumoLogic limit.
      # start context, ts
      yield
      stop context, msg, ts
    rescue => ex
      error context, msg, ex, ts
      raise ex
    end
  end
end
duration_ms(from, to = Time.now.to_f) click to toggle source
# File lib/sidekiq-ichnite/middleware.rb, line 102
def duration_ms(from, to = Time.now.to_f)
  ((to - from) * 1000).round
end
error(context, msg, error, start) click to toggle source
# File lib/sidekiq-ichnite/middleware.rb, line 78
def error(context, msg, error, start)
  data = context.merge(job_timing(msg, start))
  data.merge!(
    at: :error,
    error: error.class.name,
    message: error.message[/\A.+$/].inspect)
  ::Ichnite.log('job_error', data)
end
job_timing(msg, start) click to toggle source
# File lib/sidekiq-ichnite/middleware.rb, line 92
def job_timing(msg, start)
  # with clock drift this number can become negative.
  # Let's take 0 in this case.
  queued_duration = [0, duration_ms(msg['enqueued_at'], start)].max
  {
    queued_for: queued_duration / 1000,
    duration: duration_ms(start)
  }
end
start(context, _time) click to toggle source
# File lib/sidekiq-ichnite/middleware.rb, line 74
def start(context, _time)
  ::Ichnite.log('job_start', context)
end
stop(context, msg, start) click to toggle source
# File lib/sidekiq-ichnite/middleware.rb, line 87
def stop(context, msg, start)
  data = context.merge(job_timing(msg, start))
  ::Ichnite.log('job_stop', data)
end