4

如何将获救的异常发送到 NewRelic ?

我有一个测试文件 rpm.rb:

require 'newrelic_rpm'
NewRelic::Agent.manual_start
begin
  "2" + 3
rescue TypeError => e
  puts "whoa !"
  NewRelic::Agent.agent.error_collector.notice_error( e )
end

我开始:

NEWRELIC_ENABLE=true ruby rpm.rb

log/newrelic_agent.log的内容:

[05/14/13 ... (87691)] INFO : Reading configuration from config/newrelic.yml
[05/14/13 ... (87691)] INFO : Environment: development
[05/14/13 ... (87691)] WARN : No dispatcher detected.
[05/14/13 ... (87691)] INFO : Application: xxx (Development)
[05/14/13 ... (87691)] INFO : Installing Net instrumentation
[05/14/13 ... (87691)] INFO : Audit log enabled at '.../log/newrelic_audit.log'
[05/14/13 ... (87691)] INFO : Finished instrumentation
[05/14/13 ... (87691)] INFO : Reading configuration from config/newrelic.yml
[05/14/13 ... (87691)] INFO : Starting Agent shutdown

log/newrelic_audit.log 的内容

[2013-05-14 ... (87691)] : REQUEST: collector.newrelic.com:443/agent_listener/12/74901a11b7ff1a69aba11d1797830c8c1af41d56/get_redirect_host?marshal_format=json
[2013-05-14 ... (87691)] : REQUEST BODY: []

什么都没有报告给 NewRelic,为什么?

我已经看到了:有没有办法手动推送 NewRelic 错误?

4

2 回答 2

0

您需要monitor_mode: true在 config/newrelic.yml中设置

development:
  <<: *default_settings
  # Turn off communication to New Relic service in development mode (also
  # 'enabled').
  # NOTE: for initial evaluation purposes, you may want to temporarily
  # turn the agent on in development mode.
  monitor_mode: true

  # Rails Only - when running in Developer Mode, the New Relic Agent will
  # present performance information on the last 100 transactions you have
  # executed since starting the mongrel.
  # NOTE: There is substantial overhead when running in developer mode.
  # Do not use for production or load testing.
  developer_mode: true
于 2014-06-05T21:47:40.773 回答
0

我只花了一个小时试图从生产控制台测试这个。这就是最终让它工作的原因:

  1. 确保monitor_mode: true在 newrelic.yml 中为适当的环境设置

  2. 确保使用以下命令运行 rails 控制台NEW_RELIC_AGENT_ENABLED=true NEWRELIC_ENABLE=true rails c

  3. 确保使用 public-api 方法调用NewRelic::Agent.notice_error(exception)

自然,.notice_error当从 Web 服务器等非控制台进程调用时,它将按预期工作。

于 2018-08-14T14:18:33.930 回答