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?
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.
New Relic caps error reporting at: 100 events per minute per agent instance.
newrelic.noticeError(error object $error, [object $customAttributes]) Identifies a browser error without disrupting your app's operations.
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.
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
Not sure if it's recommended way to use, but this works perfectly:
NewRelic::Agent.agent.error_collector.notice_error( exception )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With