diff --git a/Changes.md b/Changes.md index a6eaa67d..f16fc2ff 100644 --- a/Changes.md +++ b/Changes.md @@ -8,6 +8,7 @@ HEAD - Reimplement Web UI's HTTP\_ACCEPT\_LANGUAGE parsing because the spec is utterly incomprehensible for various edge cases. [johanlunds, natematykiewicz, #3449] - Update `class_attribute` core extension to avoid warnings +- Expose `job_hash_context` from `Sidekiq::Logging` to support log customization 5.0.0 ----------- diff --git a/lib/sidekiq/logging.rb b/lib/sidekiq/logging.rb index 839d964d..0bba2c1d 100644 --- a/lib/sidekiq/logging.rb +++ b/lib/sidekiq/logging.rb @@ -26,6 +26,18 @@ module Sidekiq end end + def self.job_hash_context(job_hash) + # If we're using a wrapper class, like ActiveJob, use the "wrapped" + # attribute to expose the underlying thing. + klass = job_hash['wrapped'.freeze] || job_hash["class".freeze] + bid = job_hash['bid'.freeze] + "#{klass} JID-#{job_hash['jid'.freeze]}#{" BID-#{bid}" if bid}" + end + + def self.with_job_hash_context(job_hash, &block) + with_context(job_hash_context(job_hash), &block) + end + def self.with_context(msg) Thread.current[:sidekiq_context] ||= [] Thread.current[:sidekiq_context] << msg diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index ea841075..30766f7e 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -125,12 +125,7 @@ module Sidekiq # job structure to the Web UI pristine = cloned(job_hash) - # If we're using a wrapper class, like ActiveJob, use the "wrapped" - # attribute to expose the underlying thing. - klass = job_hash['wrapped'.freeze] || job_hash["class".freeze] - ctx = "#{klass} JID-#{job_hash['jid'.freeze]}#{" BID-#{job_hash['bid'.freeze]}" if job_hash['bid'.freeze]}" - - Sidekiq::Logging.with_context(ctx) do + Sidekiq::Logging.with_job_hash_context(job_hash) do @retrier.global(job_hash, queue) do @logging.call(job_hash, queue) do stats(pristine, queue) do