class LunaPark::Notifiers::Bugsnag

Public Class Methods

new(min_lvl: :debug) click to toggle source
# File lib/luna_park/notifiers/bugsnag.rb, line 11
def initialize(min_lvl: :debug)
  self.min_lvl = min_lvl
end

Public Instance Methods

post(msg, lvl: :error, **details) click to toggle source
# File lib/luna_park/notifiers/bugsnag.rb, line 15
def post(msg, lvl: :error, **details) # rubocop:disable Metrics/MethodLength
  raise ArgumentError, "Undefined severity level `#{lvl}`" unless LEVELS.include? lvl

  message = wrap msg
  details = extend details, with: msg
  ::Bugsnag.notify(message) do |report|
    report.add_tab(:details, details)

    if %i[fatal unknown].include? lvl
      report.add_tab(:original_message_severity, lvl)
      report.severity = :error
    else
      report.severity = lvl
    end
  end
end

Private Instance Methods

extend(details, with:) click to toggle source
# File lib/luna_park/notifiers/bugsnag.rb, line 38
def extend(details, with:)
  msg = with
  return details unless msg.respond_to?(:details)

  msg.details.merge(details) do |_, msg_value, post_value|
    { message: msg_value, post: post_value }
  end
end
wrap(msg) click to toggle source
# File lib/luna_park/notifiers/bugsnag.rb, line 34
def wrap(msg)
  msg.is_a?(Exception) ? msg : msg.inspect
end