Skip to content

A platform for community discussion. Free, open, simple.

FIX: Avoid `NoMethodError` in `DiscourseLogstashLogger` (#37253)

Alan Guo Xiang Tan7392d3e757ee
diff --git a/lib/discourse_logstash_logger.rb b/lib/discourse_logstash_logger.rb
index c4c4997749e..1f9b83629e2 100644
--- a/lib/discourse_logstash_logger.rb
+++ b/lib/discourse_logstash_logger.rb
@@ -74,9 +74,8 @@ class DiscourseLogstashLogger < Logger
# Only log backtrace and env for Logger::WARN and above.
# Backtrace is just noise for anything below that.
if severity >= Logger::WARN
- if (backtrace = opts&.dig(:backtrace)).present?
- event["backtrace"] = backtrace
- end
+ backtrace = opts&.dig(:backtrace)
+ event["backtrace"] = backtrace if backtrace && !backtrace.empty?
# `web-exception` is a log message triggered by logster.
# The exception class and message are extracted from the message based on the format logged by logster in