mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Pass more context from Sidekiq jobs to Logster
This commit is contained in:
parent
ede8f22971
commit
2b5a955c18
2 changed files with 20 additions and 9 deletions
|
@ -43,18 +43,28 @@ end
|
|||
|
||||
Sidekiq.logger.level = Logger::WARN
|
||||
|
||||
class LogsterErrorHandler
|
||||
def call(ex, hash={})
|
||||
text = "exception: #{ex}\ncontext: #{hash.inspect}\n"
|
||||
class SidekiqLogsterReporter
|
||||
def call(ex, context = {})
|
||||
# Pass context to Logster
|
||||
fake_env = {}
|
||||
context.each do |key, value|
|
||||
Logster.add_to_env(fake_env, key, value)
|
||||
end
|
||||
|
||||
text = "Job exception: #{ex}\n"
|
||||
if ex.backtrace
|
||||
text << "backtrace: #{ex.backtrace.join("\n")}"
|
||||
Logster.add_to_env(fake_env, :backtrace, ex.backtrace)
|
||||
end
|
||||
Rails.logger.error(text)
|
||||
|
||||
Thread.current[Logster::Logger::LOGSTER_ENV] = fake_env
|
||||
Logster.logger.error(text)
|
||||
rescue => e
|
||||
Rails.logger.fatal("Failed to log exception #{ex} #{hash}\nReason: #{e}\n#{e.backtrace.join("\n")}")
|
||||
Logster.logger.fatal("Failed to log exception #{ex} #{hash}\nReason: #{e.class} #{e}\n#{e.backtrace.join("\n")}")
|
||||
ensure
|
||||
Thread.current[Logster::Logger::LOGSTER_ENV] = nil
|
||||
end
|
||||
end
|
||||
|
||||
Sidekiq.error_handlers << LogsterErrorHandler.new
|
||||
Sidekiq.error_handlers << SidekiqLogsterReporter.new
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ module Discourse
|
|||
extend Sidekiq::ExceptionHandler
|
||||
end
|
||||
|
||||
# Responsible for exceptions in Sidekiq jobs - not requests!
|
||||
def self.handle_exception(ex, context = nil, parent_logger = nil)
|
||||
context ||= {}
|
||||
parent_logger ||= SidekiqExceptionHandler
|
||||
|
|
Loading…
Reference in a new issue