Home > other >  can an app monitored by New Relic explicitly generate an incident alert from inside itself?
can an app monitored by New Relic explicitly generate an incident alert from inside itself?

Time:05-26

I'm using New Relic (Heroku add-on) to monitor a Rails app. There is a place in the app that detects a "this should never happen" condition that's not easily detectable via New Relic's monitoring, and I'd like to be able to use New Relic notifications/alerts/whatever to immediately send up a flare in that code path. Is there a way to explicitly trigger an alert from within an app, so that I don't have to add another gem/plugin just for incident alerts?

(This seems similar to this 2013 question that was never definitively answered and whose links in comments are now stale)

CodePudding user response:

You can use NewRelic::Agent.record_custom_event or NewRelic::Agent.notice_error methods.

CodePudding user response:

I'd do something like this:

begin
  this_should_never_happen
rescue Exception
  if defined?(NewRelic)
    error = StandardError.new('Boom!')
    NewRelic::Agent.notice_error(error)
  end
end
  • Related