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?
Is there way to push NewRelic error manually?
Asked Answered
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
Here's the documentation for this: rdoc.info/github/newrelic/rpm/NewRelic/Agent:notice_error It's basically an alias to the method Igor included in his solution, except it returns nil instead of the exception. So while it behaves a little differently, it's essentially the same thing and much less verbose. –
Otiliaotina
To add more context I precede that with: NewRelic::Agent.add_custom_attributes({ custom_params: params.to_unsafe_h.merge(current_user: current_user.id), uri: request.original_url }) –
Mcfadden
Not sure if it's recommended way to use, but this works perfectly:
NewRelic::Agent.agent.error_collector.notice_error( exception )
I work at New Relic. While this method may work today, it is not part of our public API, and thus shouldn't be used - it may change at any point in the future. The correct method to use is
NewRelic::Agent.notice_error
, as noted in nort's response. Anything that's not documented in our public API docs falls into the same category. –
Brythonic Full documentation of the API call to notice errors and increment the error metric is the New Relic Ruby Agent API documentation here http://rdoc.info/github/newrelic/rpm/NewRelic/Agent/Transaction.notice_error
© 2022 - 2024 — McMap. All rights reserved.