-
Notifications
You must be signed in to change notification settings - Fork 69
fix(agent): fix Drupal error and exception handling #995
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
Changes from 1 commit
955697b
dfd1392
47a930d
7ab64fb
82ec0d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#include "php_user_instrument.h" | ||
#include "php_execute.h" | ||
#include "php_wrapper.h" | ||
#include "php_error.h" | ||
#include "fw_drupal_common.h" | ||
#include "fw_hooks.h" | ||
#include "fw_support.h" | ||
|
@@ -20,6 +21,60 @@ | |
|
||
#define PHP_PACKAGE_NAME "drupal/core" | ||
|
||
NR_PHP_WRAPPER(nr_drupal_exception) { | ||
int priority = nr_php_error_get_priority(E_ERROR); | ||
zval* event = NULL; | ||
zval* exception = NULL; | ||
|
||
/* Warning avoidance */ | ||
(void)wraprec; | ||
|
||
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK(NR_FW_DRUPAL8); | ||
|
||
if (NR_SUCCESS != nr_txn_record_error_worthy(NRPRG(txn), priority)) { | ||
NR_PHP_WRAPPER_CALL; | ||
goto end; | ||
} | ||
|
||
/* Get the event that was given. */ | ||
event = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS TSRMLS_CC); | ||
bduranleau-nr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
/* Call the original function. */ | ||
NR_PHP_WRAPPER_CALL; | ||
|
||
if (0 == nr_php_is_zval_valid_object(event)) { | ||
nrl_verbosedebug(NRL_TXN, | ||
"Drupal: ExceptionSubscriber::onException() does not " | ||
"have an `event` parameter"); | ||
goto end; | ||
} | ||
|
||
/* | ||
* Get the exception from the event. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code seems to rely on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe this is outside the scope of this PR. We use
The very first call in |
||
exception = nr_php_call(event, "getThrowable"); | ||
if (!nr_php_is_zval_valid_object(exception)) { | ||
exception = nr_php_call(event, "getException"); | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (!nr_php_is_zval_valid_object(exception)) { | ||
nrl_verbosedebug(NRL_TXN, "Drupal: getException() returned a non-object"); | ||
goto end; | ||
} | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (NR_SUCCESS | ||
!= nr_php_error_record_exception(NRPRG(txn), exception, priority, true, | ||
NULL, | ||
&NRPRG(exception_filters) TSRMLS_CC)) { | ||
bduranleau-nr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
nrl_verbosedebug(NRL_TXN, "Drupal: unable to record exception"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be higher priority than |
||
} | ||
|
||
end: | ||
nr_php_arg_release(&event); | ||
nr_php_zval_free(&exception); | ||
} | ||
NR_PHP_WRAPPER_END | ||
|
||
/* | ||
* Purpose : Convenience function to handle adding a callback to a method, | ||
* given a class entry and a method name. This will check the | ||
|
@@ -730,6 +785,32 @@ void nr_drupal8_enable(TSRMLS_D) { | |
"er::getControllerFromDefinition"), | ||
nr_drupal8_name_the_wt TSRMLS_CC); | ||
|
||
/* | ||
* ExceptionSubscribers handle Drupal errors and exceptions before | ||
* the agent has the opportunity to capture them. Instrument several | ||
* of these ExceptionSubscriber function `onException` methods in order | ||
* to capture Exceptions and Errors in Drupal 9.x+ | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
// clang-format off | ||
/* | ||
* Utility base class for exception subscribers. | ||
*/ | ||
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\HttpExceptionSubscriberBase::onException"), | ||
nr_drupal_exception); | ||
|
||
/* | ||
* Log exceptions without further handling. | ||
*/ | ||
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\ExceptionLoggingSubscriber::onException"), | ||
nr_drupal_exception); | ||
|
||
/* | ||
* Last-chance handler for exceptions: the final exception subscriber. | ||
*/ | ||
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\FinalExceptionSubscriber::onException"), | ||
nr_drupal_exception); | ||
// clang-format on | ||
|
||
/* | ||
* The drupal_modules config setting controls instrumentation of modules, | ||
* hooks, and views. | ||
|
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.
Should this use a variation of the
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK
macro (which doesnt yet exist) to make sure a compatible version of Drupal is present? This works with 9+ correct?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.
This fixes exceptions for 8 and exceptions and errors for 9+. For Drupal 8 errors, this code has no impact (positive or negative) as the problem with error reporting originates from this block unique to pre-oapi instrumentation, and D8 is only compatible with PHP up to 7.4.