-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(agent): improve exception handler instrumentation for PHPs 8.0+ #877
fix(agent): improve exception handler instrumentation for PHPs 8.0+ #877
Conversation
This test reproduces the issue of the agent not recording the error when exception handler calls restore_exception_handler.
When user exception handler is installed it can call restore_exception_handler, and that will reset is_exception_handler flag in the wraprec which will cause the agent not to use the correct code path after user exception handler returns. The information that `nr_php_instrument_func_end` is handling return from user exception handler needs to be stored in the segment associated with the user exception handler.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #877 +/- ##
=======================================
Coverage 78.76% 78.76%
=======================================
Files 193 193
Lines 27125 27129 +4
=======================================
+ Hits 21365 21369 +4
Misses 5760 5760
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Agent for PHPs 8.0+ uses observer API to hook into Zend Engine, which allows offers better out-of-the-box instrumentation of user exception handler. When observer API is used, there's no need to wrap exception handlers to record errors.
There's no need to check if wraprec is not NULL - it is guaranteed to be not NULL at this point.
tests/integration/errors/test_oapi_uncaught_handled_exception_04.php
Outdated
Show resolved
Hide resolved
tests/integration/errors/test_oapi_uncaught_handled_exception_04.php
Outdated
Show resolved
Hide resolved
Co-authored-by: ZNeumann <[email protected]>
Do you have an idea what is causing the 8.3 failure?
|
@zsistla Good eye! This means that PHP 8.3 started to behave like I would expect all PHPs to behave, that is honor the exception handler's stack. That was the purpose of this test! I remember reading about it somewhere... I need to split this test into two tests: for PHPs < 8.3 and for PHPs >= 8.3. |
@zsistla This is really broken in PHP. Even not all versions of PHP 8.3 behave the same: https://3v4l.org/ARJ9A |
PHP 8.3 introduced changes to handling exceptions and honoring exception handler stack. Add tests that illustrate those behavior differences.
Tried to address this with 4646c9c. |
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.3", "<")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test is named php835, but this just checks for 8.3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to properly name the test files that need to run for PHPs 8.3.0-8.3.4 (currently the test is named tests/integration/errors/test_oapi_uncaught_handled_exception_04.php83.php
) vs test files that run correctly for all 8.3.x PHPs. I'm open to suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 835 naming convention was perfectly fine, but the 835 test only had this check:
<?php
if (version_compare(PHP_VERSION, "8.3", "<")) {
die("skip: PHP < 8.3.0 not supported\n");
}
shouldn't it be
if (version_compare(PHP_VERSION, "8.3.5", "<")) {
die("skip: PHP < 8.3.5 not supported\n");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed 835 meant php 8.3.5 and above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of in the name, update the description inside the test explaining why the skipif and which versions we expect it to run on.
Then you can have an 83a, 83b, etc to indicate it is the same test but differences are needed due to variants 8.3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestions. See 5013256.
Not a blocker, but why do the text cases need |
I included |
Explain why different tests are needed in test description rather than test filename.
Removed |
LGTM! |
When user exception handler is installed it can call restore_exception_handler,
and that will reset is_exception_handler flag in the wraprec which will cause
the agent not to use the correct code path after user exception handler returns.
The information that
nr_php_instrument_func_end
is handling return from userexception handler needs to be stored in the segment associated with the user
exception handler.