【问题标题】:How to send manually exceptions to NewRelic (Ruby)?如何手动向 NewRelic (Ruby) 发送异常?
【发布时间】:2013-05-08 11:42:54
【问题描述】:

如何将已获救的异常发送到 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?

【问题讨论】:

  • raise 关键字有帮助吗?
  • 我不想让我们的客户看到堆栈跟踪 :),这就是为什么在我的示例中进行救援的原因,但是谢谢
  • 这可能太明显了,但是NR在开发模式下默认不会打电话回家,除非你改变配置文件。
  • 这似乎被WARN : No dispatcher detected.证实了
  • 我在 New Relic 的 newrelic_rpm gem 上工作。您使用的是什么版本的 newrelic_rpm gem?除非检测到已知的调度程序(Web 服务器或后台任务框架),否则旧版本将完全拒绝启动,并且看起来您可能已经成功了。此外,您应该使用NewRelic::Agent.notice_error,因为这是我们的公共 API,而不是 error_collector 上的版本。

标签: ruby exception newrelic


【解决方案1】:

你需要在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

【讨论】:

    【解决方案2】:

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

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

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

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

    当然,.notice_error 在从网络服务器等非控制台进程调用时会按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多