Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there way to push NewRelic error manually?

In our Rails app we rescue most of the exceptions on ApplicationController to give correct API response, but still want to track errors happening using ErrorCollector. Is there a way to manually send error to NewRelic?

like image 592
Igor R. Avatar asked Sep 26 '12 17:09

Igor R.


People also ask

How do you send errors to New Relic?

To send error data that you are handling in your own code to New Relic, use the Ruby agent API NewRelic::Agent. notice_error call within your error handler.

What is error rate in New Relic?

New Relic caps error reporting at: 100 events per minute per agent instance.

What is New Relic noticeError?

newrelic.noticeError(error object $error, [object $customAttributes]) Identifies a browser error without disrupting your app's operations.

How do I stop New Relic?

There are two main ways to disable the Go agent: Remove the import of the github.com/newrelic/go-agent package from your application, and remove or comment out any calls to the newrelic namespace. Then, recompile and restart your app. Use the enabled configuration setting.


2 Answers

Based on what I see in the New Relic agent code you can do

NewRelic::Agent.notice_error(exception, options)

I have tested this and have this running in my stack

Here's an example in a controller:

class ApplicationController < ActionController::Base   rescue_from ActiveRecord::RecordInvalid, with: :rescue_invalid_record    private    def rescue_invalid_record(exception)     NewRelic::Agent.notice_error(exception)   end end 
like image 196
nort Avatar answered Sep 16 '22 16:09

nort


Not sure if it's recommended way to use, but this works perfectly:

NewRelic::Agent.agent.error_collector.notice_error( exception ) 
like image 30
Igor R. Avatar answered Sep 17 '22 16:09

Igor R.