Is there way to push NewRelic error manually?

老子叫甜甜 提交于 2019-12-04 15:17:29

问题


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?


回答1:


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



回答2:


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

NewRelic::Agent.agent.error_collector.notice_error( exception )



回答3:


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



来源:https://stackoverflow.com/questions/12607321/is-there-way-to-push-newrelic-error-manually

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!