mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Extract Processor#log_context to ease extending what's logged (#3463)
* Extract Processor#log_context to ease extending what's logged
This was previously exposed in JobLogger and Middleware::Server::Logging
but was inlined into Processor.
701e06224c
Useful, e.g. in this case:
https://github.com/mperham/sidekiq/issues/1786
* Move job hash context logic into Sidekiq::Logging
This commit is contained in:
parent
2a8df9c256
commit
fb8fdc3687
3 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
-----------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue