Armando Fox
Armando Fox

Reputation: 309

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

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)

Upvotes: 0

Views: 194

Answers (2)

user1032752
user1032752

Reputation: 871

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

Upvotes: 1

flh
flh

Reputation: 41

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

Upvotes: 3

Related Questions