astropanic
astropanic

Reputation: 10939

How to send manually exceptions to NewRelic (Ruby)?

How I can send rescued exceptions to NewRelic ?

I have a test file 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

I start it with:

NEWRELIC_ENABLE=true ruby rpm.rb

The content of 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

The content of 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: []

Nothing is reported to NewRelic, why ?

I saw this already: Is there way to push NewRelic error manually?

Upvotes: 4

Views: 2045

Answers (2)

Epigene
Epigene

Reputation: 3908

I just spent an hour trying to test this from production console. This is what finally got it working:

  1. Make sure monitor_mode: true is set in newrelic.yml for the appropriate environment

  2. Make sure to run the rails console with NEW_RELIC_AGENT_ENABLED=true NEWRELIC_ENABLE=true rails c

  3. Make sure to use the public-api method call NewRelic::Agent.notice_error(exception)

Naturally, .notice_error will work as expected when called from a non-console process like the web-server.

Upvotes: 1

Zhomart
Zhomart

Reputation: 742

You need to set monitor_mode: true in 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

Upvotes: 0

Related Questions