Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Feature Idea: Show previous exceptions



Please share your agent version and other relevant versions below:

NewRelic agent version:
PHP: 7.1.2

Please share your question/describe your issue below. Include any screenshots that may help us understand your question:

Our framework (Zend Framework) will catch exceptions thrown during service creation. And then throw new a new Exception (of a different type), with the caught exception as previous exception.

NewRelic only shows the last exception. For example, we can only see the following error information:

Zend\ServiceManager\Exception\ServiceNotCreatedException: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotCreatedException' with message 'An exception was raised while creating "Zend\Mvc\View\Http\DefaultRenderingStrategy"; no instance returned' in /vendor/zendframework/zend-servicemanager/src/ServiceManager.php:941

And we cannot trace the actual error, and it’s own stack trace.

Is it possible to show these previous exceptions?

On my site, I have a set of URLs for Google AMP equivalent pages for my blog posts. The New Relic APM PHP Agent is automatically adding a script tag to every page. However, this is not allowed on AMP pages.

How can I prevent the agent from adding the script to specific urls on my site?

New Relic edit

  • I want this, too
  • I have more info to share (reply below)
  • I have a solution for this

0 voters

We take feature ideas seriously and our product managers review every one when plotting their roadmaps. However, there is no guarantee this feature will be implemented. This post ensures the idea is put on the table and discussed though. So please vote and share your extra details with our team.


@roel It is but it requires you to manually send us the error in that code that handles the error.

So before it rethrows that new error, take the old error and use newrelic_notice_error() API function and send it to New Relic.

The downside is you’ll have double error reporting, the first error and the rethrown error, but you will get the detail you’re looking for.


Can you provide how we can do this? We now use register_shutdown_function to enhance the error information (for example with newrelic_add_custom_parameter). However; at that point in time we cannot seem to access the Exception itself.

May I ask why you chosen this behaviour? As it deviates from the way PHP shows and reports the error to the browser.


Unfortunately, newrelic_notice_error() can only be called once during a request. If you call it multiple times, it will only give us the exception from the last call to newrelic_notice_error(). And in most of our use cases, we want all of the exceptions (not just the first or the last).

Also, it only preserves the stack trace from when you call newrelic_notice_error(), not the stack trace that comes with the actual exception. Which essentially makes it useless for our purposes (firing it in the shutdown function).


@roel, Currently, the agent will report the last error when newrelic_notice_error is called
multiple times with the same error priority, as in E_WARNING, E_ERROR, etc. I’ve gone ahead and filed a feature request on your behalf to be able to capture any and all errors associated with a single transaction.


Wouldn’t it be better to improve the original error being reported? Thus: only the original exception. Even better: show both the original and the ones that compose the others.


Thanks for that extra level of details @roel - I will make sure it’s added to your feature idea with engineering.


Chaining exceptions is used inside frameworks/libraries and is present in most programming languages.
Throwable interface has function getPrevious(): Throwable that is often used when displaying error creating meaningfull (but long) stack traces like:

Propel\Runtime\Exception\PropelException: Unable to execute INSERT statement [INSERT INTO …]
…/Product.php:3390 in …\Product->doInsert
…/Product.php:2831 in …\Product->doSave
Caused by PDOException: SQLSTATE[HY000]: General error: 1364 Field 'availability' doesnt have a default value
…/vendor/propel/propel/src/Propel/Runtime/Adapter/Pdo/PdoStatement.php:57 in PDOStatement->execute

I can’t use NewRelic for analyzing errors due to this


I am in this situation as well. PHP enables you to chain exceptions, but newrelic_notice_error() ignores previous exceptions and only displays the latest one. Calling newrelic_notice_error() for every step in the chaining process is the wrong approach IMHO, as the information gets chopped into several exceptions, and you have to piece it together manually…


This should be enabled by default. This should be displayed with that one error report (not multiple ones). Please fix this (I would say this is not a feature request but a bug report).


Same problem here. We catch exceptions in our controllers and then throw a custom built ControllerException with some extra parameters from the controller (like is the user logged in, what user ID it is, etc) and currently it makes New Relic errors completely broken.

I really don’t want to change my code just to make New Relic work properly.

I agree.


Thanks for the feedback @henry10 - I will make sure that gets to the team.