Skip to content

Manually log errors in New Relic

For debugging purposes, custom errors can be manually logged in PHP code using the trigger_error() function, along with a minimum error level (second argument) of E_USER_WARNING. The default is E_USER_NOTICE.

On VIP Platform WordPress environments, custom errors can be logged in New Relic using newrelic_notice_error().

Errors can be triggered with code similar to this example:

if ( extension_loaded( 'newrelic' ) ) {
    newrelic_notice_error( 'My custom error message' );
}

For more information, refer to New Relic’s function documentation.

Note

If there are multiple calls to newrelic_notice_error() in a single transaction, the PHP agent will retain the exception from the last call only.

Alternatively, the newrelic_record_custom_event() function can be used to keep track of data and log events without considering it to be an error.

For more information, refer to New Relic’s function documentation for newrelic_record_custom_event().

NewRelic’s Ingest API can be used to report custom telemetry data including custom events using an HTTP POST request method. This method provides a response status code that can be used to track the reliability of the ingested data.

Last updated: May 05, 2022