Question: Sidekiq logs show JobWrapper instead of Job class name

Question

Sidekiq logs show JobWrapper instead of Job class name

Answers 2
Added at 2016-10-18 13:10
Tags
Question

I have a Rails application that runs some background jobs via ActiveJob and Sidekiq. The sidekiq logs in both the terminal and the log file show the following:

2016-10-18T06:17:01.911Z 3252 TID-oukzs4q3k ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-97318b38b1391672d21feb93 INFO: start

Is there some way to show the class names of the jobs here similar to how logs work for a regular Sidekiq Worker?

Update:

Here is how a Sidekiq worker logs:

2016-10-18T11:05:39.690Z 13678 TID-or4o9w2o4 ClientJob JID-b3c71c9c63fe0c6d29fd2f21 INFO: start

Update 2:

My sidekiq version is 3.4.2

I'd like to replace ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper with Client Job

Answers
nr: #1 dodano: 2016-10-18 16:10

You must be running some ancient version. Upgrade.

Sorry, looks like that's a Rails 5+ feature only. You'll need to upgrade Rails. https://github.com/rails/rails/commit/8d2b1406bc201d8705e931b6f043441930f2e8ac

nr: #2 dodano: 2016-10-19 13:10

So I managed to do this by removing Sidekiq::Middleware::Server::Logging from the middleware configuration and adding a modified class that displays the arguments in the logs. The arguments themself contain the job and action names as well.

For latest version, currently 4.2.3, in sidekiq.rb

require 'sidekiq'
require 'sidekiq/middleware/server/logging'

class ParamsLogging < Sidekiq::Middleware::Server::Logging
  def log_context(worker, item)
    klass = item['wrapped'.freeze] || worker.class.to_s
    "#{klass} (#{item['args'].try(:join, ' ')}) JID-#{item['jid'.freeze]}"
  end
end

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.remove Sidekiq::Middleware::Server::Logging
    chain.add ParamsLogging
  end
end

For version 3.4.2, or similar, override the call method instead:

class ParamsLogging < Sidekiq::Middleware::Server::Logging
  def call(worker, item, queue)
    klass = item['wrapped'.freeze] || worker.class.to_s
    Sidekiq::Logging.with_context("#{klass} (#{item['args'].try(:join, ' ')}) JID-#{item['jid'.freeze]}") do
      begin
        start = Time.now
        logger.info { "start" }
        yield
        logger.info { "done: #{elapsed(start)} sec" }
      rescue Exception
        logger.info { "fail: #{elapsed(start)} sec" }
        raise
      end
    end
  end
end
Source Show
◀ Wstecz