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
|
Sidekiq.logger.level = Logger::WARN
|
||||||
|
|
||||||
class LogsterErrorHandler
|
class SidekiqLogsterReporter
|
||||||
def call(ex, hash={})
|
def call(ex, context = {})
|
||||||
text = "exception: #{ex}\ncontext: #{hash.inspect}\n"
|
# Pass context to Logster
|
||||||
if ex.backtrace
|
fake_env = {}
|
||||||
text << "backtrace: #{ex.backtrace.join("\n")}"
|
context.each do |key, value|
|
||||||
|
Logster.add_to_env(fake_env, key, value)
|
||||||
end
|
end
|
||||||
Rails.logger.error(text)
|
|
||||||
|
text = "Job exception: #{ex}\n"
|
||||||
|
if ex.backtrace
|
||||||
|
Logster.add_to_env(fake_env, :backtrace, ex.backtrace)
|
||||||
|
end
|
||||||
|
|
||||||
|
Thread.current[Logster::Logger::LOGSTER_ENV] = fake_env
|
||||||
|
Logster.logger.error(text)
|
||||||
rescue => e
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
Sidekiq.error_handlers << LogsterErrorHandler.new
|
Sidekiq.error_handlers << SidekiqLogsterReporter.new
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ module Discourse
|
||||||
extend Sidekiq::ExceptionHandler
|
extend Sidekiq::ExceptionHandler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.handle_exception(ex, context=nil, parent_logger = nil)
|
# Responsible for exceptions in Sidekiq jobs - not requests!
|
||||||
|
def self.handle_exception(ex, context = nil, parent_logger = nil)
|
||||||
context ||= {}
|
context ||= {}
|
||||||
parent_logger ||= SidekiqExceptionHandler
|
parent_logger ||= SidekiqExceptionHandler
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue