-
Notifications
You must be signed in to change notification settings - Fork 21
Description
(Edit: Rephrased the issue to only change the message, but keep the "class" value unchanged, since other logic might depend on it.)
Given in Rails, with Sidekiq < 81, some active job:
class SomeWorker < ApplicationJob
(where ApplicationJob < ActiveJob::Base
), Sidekiq::Logstash prepares a JSON hash with
{ "message":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-3be139c4f7f876ca929ad660: done: 0.123 sec", "class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", wrapped: "SomeWorker", ... }
I'd rather expect the unwrapped class in the message:
{ "message":"SomeWorker JID-3be139c4f7f876ca929ad660: done: 0.123 sec", "class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", wrapped: "SomeWorker", ... }
The original Sidekiq::JobLogger handles that by taking into account several potential sources for the class
-attribute:
class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
As far as I can see, the fix should simply be a modified line in setup_payload
, namely
payload['message'] = "#{payload['display_class'] || payload['wrapped'] || payload['class']} JID-#{payload['jid']}"
instead of
payload['message'] = "#{payload['class']} JID-#{payload['jid']}"
I don't think custom_options
could be used to make this work either, since the message is constructed in several steps.
My workaround is this patch:
require 'sidekiq/logging/shared'
module Sidekiq
module Logging
module SharedPatch
private def setup_payload(job)
payload = super
payload['message'] = "#{payload['display_class'] || payload['wrapped'] || payload['class']} JID-#{payload['jid']}"
payload
end
end
Shared.prepend(SharedPatch)
end
end
Initially, I tried to provide a PR, but I did not know how to best setup a test harness with an ActiveJob to demonstrate it. I hope this description at least can serve as a starting point.
Footnotes
-
Sidekiq 8 changes
ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
toSidekiq::ActiveJob::Wrapper
2, apart from that the issue remains the same. ↩ -
https://github.com/sidekiq/sidekiq/blob/main/Changes.md#800 ↩