DEV: Improve logging of Sidekiq errors when logstash logger is enabled (#27855)

This commit improves the logging of Sidekiq errors when
`ENABLE_LOGSTASH_LOGGER` is set to 1. Prior to this change, we would
only log the message and the backtrace. After this change, useful
information like `job.class`, `job.opts`, `job.problem_db`,
`exception.class` and `exception.message` are included in the log line
as well.
This commit is contained in:
Alan Guo Xiang Tan
2024-07-11 14:17:18 +08:00
committed by GitHub
parent 7b627dc14b
commit 66878a9e80
3 changed files with 109 additions and 79 deletions

View File

@ -91,12 +91,18 @@ class DiscourseLogstashLogger < Logger
event["exception.class"] = $1
event["exception.message"] = $2.strip
end
ALLOWED_HEADERS_FROM_ENV.each do |header|
event["request.headers.#{header.downcase}"] = opts.dig(:env, header)
end
end
if (env = opts&.dig(:env)).present?
ALLOWED_HEADERS_FROM_ENV.each do |header|
event["request.headers.#{header.downcase}"] = opts[:env][header]
end
if progname == "sidekiq-exception"
event["job.class"] = opts.dig(:context, :job)
event["job.opts"] = opts.dig(:context, :opts)
event["job.problem_db"] = opts.dig(:context, :problem_db)
event["exception.class"] = opts[:exception_class]
event["exception.message"] = opts[:exception_message]
end
end