Is there way to push NewRelic error manually?

前端 未结 3 812
我寻月下人不归
我寻月下人不归 2021-02-11 19:28

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

3条回答
  •  被撕碎了的回忆
    2021-02-11 20:22

    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
    

提交回复
热议问题