Capture ALL uncaught exceptions as exceptions#1462
Open
dave-newson wants to merge 1 commit intoelastic:mainfrom
Open
Capture ALL uncaught exceptions as exceptions#1462dave-newson wants to merge 1 commit intoelastic:mainfrom
dave-newson wants to merge 1 commit intoelastic:mainfrom
Conversation
|
💚 CLA has been signed |
🤖 GitHub commentsJust comment with:
|
… all Uncaught throwables are accurately captured if they emit to the native handler.
5474690 to
392c2ba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue in the native uncaught exception handling, where only the
\Exceptionclass was eligible for decomposition into a verbose exception capture, leaving all other Throwables to capture as flat errors.This change now matches the FQCN of
lastThrownback to theUncaught <FQCN>:in an effort to capture ALL exception types, and the specifically relevant exception.What was happening?
We have some pre-framework code super early which
throws new \RuntimeException(, and APM was seeing this as a flat error rather than an Exception with a trace, unlike everything else we have going into APM.This was traced back to the explicit
Uncaught Exception:prefix test not matching what PHP emits:Uncaught RuntimeException:In APM this becomes an Error with the full stack-trace in the Message, and N/A for the origin function, with no Exception detailing. In turn, this representation really messes with Error Grouping and causes a lot of duplication in APM.
Why match the FQCN?
lastThrownisn't diligently unset, there's some opportunity for it to be populated when various event handlers get fired. The FQCN comparison is intended to ensure thelastThrownis definitely the same Exception mentioned in the native "Uncaught" message.FQCN matching seems to work for even namespaced throwables: https://3v4l.org/lrIIP#veol
Why hasn't anyone else seen this?
I'd wager that if you're using APM you're probably also using some kind of Framework with its own error-capture, and you'll then be using a library to augment APM with more telemetry, and this goes through a lot of non-php-native-paths to register the Exception with APM (eg.
ElasticApm::createErrorFromThrowable), and code almost never lets an Exception escape to the native PHP handler.Only when a non-\Exception type is thrown and truly uncaught, does this kick in.
Oh god the test case
I didn't want to disrupt the existing uncaught exception test case, so the test case you see added is just a duplication of the existing Uncaught Exception test. In all honesty this should probably become a dataProvider thing, but I didn't want to make it painful to validate the fix. Better to add the fix and then refactor the test cases.