如何手动向NewRelic(Ruby)发送异常?

时间:2013-05-14 09:02:04

标签: ruby exception newrelic

如何将获救的例外发送给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报告?

我已经看到了这个:Is there way to push NewRelic error manually?

2 个答案:

答案 0 :(得分:0)

您需要在config / newrelic.yml

中设置monitor_mode: true
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

答案 1 :(得分:0)

我只花了一个小时尝试从生产控制台进行测试。 这终于使它起作用了:

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

  2. 确保使用NEW_RELIC_AGENT_ENABLED=true NEWRELIC_ENABLE=true rails c

  3. 运行Rails控制台
  4. 确保使用public-api方法调用NewRelic::Agent.notice_error(exception)

自然,从诸如Web服务器之类的非控制台进程中调用时,.notice_error会按预期工作。