Sending New Relic handled errors

Problem

You're handling an error in your own code, but you want to see the error data in New Relic.

Solution

Use the Ruby Agent API NewRelic::Agent.notice_error within your error handler. This tells the agent to send the error data to New Relic.

This API call takes the exception and an optional options hash. Use this format:

notice_error(exception, options = { })

This function records the given error and passes it through the normal error filtering process, including configuration-based ignoring of errors and the global #ignore_error_filter method if defined.

The exception is the exception to be recorded, or an error message. If needed, you can also include options = { }. The following parameters will receive special treatment, and any other parameters you supply will be treated as custom parameters.

options = { } Comments
:trace_only Only record the error trace. (Do not affect error rate or Apdex status.)
:custom_params

Custom parameters.

:uri

The request path, minus any request parameters or query string.

Usually not needed. Include this only if you are calling notice_error outside a transaction.

:metric

The metric name associated with the transaction.

Usually not needed. Include this only if you are calling notice_error outside a transaction.

:request_params (deprecated) Older Ruby agent versions allowed passing a :request_params option, but those are now ignored. If you need to record the request parameters, call this method inside a transaction, or pass the information in :custom_params.

For more help

Additional documentation resources include:

Join the discussion about Ruby in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.