有没有办法手动推送NewRelic错误?

在我们的Rails应用程序中,我们拯救ApplicationController上的大多数exception以提供正确的API响应,但仍希望使用ErrorCollector跟踪发生的错误。 有没有办法手动向NewRelic发送错误?

基于我在New Relic代理中看到的内容,您可以做到

NewRelic::Agent.notice_error(exception, options)

我测试了这个,并在我的堆栈中运行

这是控制器中的一个例子:

 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 

不确定是否推荐使用方法,但这完美地运作:

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

关于通知错误和增加错误度量的API调用的完整文档是这里的新Relic Ruby代理API文档http://rdoc.info/github/newrelic/rpm/NewRelic/Agent/Transaction.notice_error