Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add exception handler fcall_end
  • Loading branch information
ZNeumann authored and lavarou committed Nov 6, 2024
commit 61fd2254ebb9baf716d559dc45350192ba2f07b9
24 changes: 16 additions & 8 deletions agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO) {
bool create_metric = false;
nr_php_execute_metadata_t metadata = {0};
#else
static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, bool end_segment) {
static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, bool end_segment, bool is_exception_handler) {
#endif
nr_segment_t* segment = NULL;
nrtime_t txn_start_time = 0;
Expand Down Expand Up @@ -2093,8 +2093,10 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, boo

#if ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO
wraprec = segment->wraprec;

if (segment->is_exception_handler) {
#else
if (is_exception_handler) {
#endif
/*
* After running the exception handler segment, create an error from
* the exception it handled, and save the error in the transaction.
Expand All @@ -2108,9 +2110,10 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, boo
nr_php_error_record_exception(
NRPRG(txn), exception, nr_php_error_get_priority(E_ERROR), false,
"Uncaught exception ", &NRPRG(exception_filters) TSRMLS_CC);
#if ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO
} else if (NULL == nr_php_get_return_value(NR_EXECUTE_ORIG_ARGS)) {
#else
if (NULL == func_return_value) {
} else if (NULL == func_return_value) {
#endif
/*
* Having no return value (and not being an exception handler) indicates
Expand Down Expand Up @@ -2250,7 +2253,8 @@ void nr_php_observer_fcall_begin(zend_execute_data* execute_data) {
static void nr_php_observer_fcall_end_common(zend_execute_data* execute_data,
zval* func_return_value,
bool create_metric,
bool end_segment) {
bool end_segment,
bool is_exception_handler) {
#else
void nr_php_observer_fcall_end(zend_execute_data* execute_data,
zval* func_return_value) {
Expand Down Expand Up @@ -2281,7 +2285,7 @@ void nr_php_observer_fcall_end(zend_execute_data* execute_data,
}

#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
nr_php_instrument_func_end(NR_EXECUTE_ORIG_ARGS, create_metric, end_segment);
nr_php_instrument_func_end(NR_EXECUTE_ORIG_ARGS, create_metric, end_segment, is_exception_handler);
#else
nr_php_instrument_func_end(NR_EXECUTE_ORIG_ARGS);
#endif
Expand All @@ -2301,15 +2305,19 @@ void nr_php_observer_fcall_begin_instrumented(zend_execute_data* execute_data) {
}
void nr_php_observer_fcall_end(zend_execute_data* execute_data,
zval* func_return_value) {
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, true);
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, true, false);
}
void nr_php_observer_fcall_end_create_metric(zend_execute_data* execute_data,
zval* func_return_value) {
nr_php_observer_fcall_end_common(execute_data, func_return_value, true, true);
nr_php_observer_fcall_end_common(execute_data, func_return_value, true, true, false);
}
void nr_php_observer_fcall_end_keep_segment(zend_execute_data* execute_data,
zval* func_return_value) {
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, false);
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, false, false);
}
void nr_php_observer_fcall_end_exception_handler(zend_execute_data* execute_data,
zval* func_return_value) {
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, true, true);
}

// These empty functions (rather than NULL) are used to know if instrumentation
Expand Down
12 changes: 8 additions & 4 deletions agent/php_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ static zend_observer_fcall_handlers nr_php_fcall_register_handlers(
nr_php_observer_fcall_begin_instrumented;
handlers.end = wraprec->special_instrumentation ?
(zend_observer_fcall_end_handler)wraprec->special_instrumentation :
wraprec->create_metric ?
nr_php_observer_fcall_end_create_metric :
nr_php_observer_fcall_end;
wraprec->is_exception_handler ?
nr_php_observer_fcall_end_exception_handler :
wraprec->create_metric ?
nr_php_observer_fcall_end_create_metric :
nr_php_observer_fcall_end;
return handlers;
}

Expand Down Expand Up @@ -152,7 +154,9 @@ void nr_php_observer_overwrite_handlers(zend_function* func, nruserfn_t* wraprec
nr_php_observer_empty_fcall_end)) {
zend_observer_add_end_handler(func, wraprec->special_instrumentation ?
(zend_observer_fcall_end_handler)wraprec->special_instrumentation :
nr_php_observer_fcall_end);
wraprec->is_exception_handler ?
nr_php_observer_fcall_end_exception_handler :
nr_php_observer_fcall_end);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions agent/php_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ void nr_php_observer_empty_fcall_end(zend_execute_data* execute_data,
zval* func_return_value);
void nr_php_observer_fcall_begin_late(zend_execute_data* execute_data, nrtime_t txn_start_time);
void nr_php_observer_fcall_end_keep_segment(zend_execute_data* execute_data,
zval* func_return_value);
zval* func_return_value);
void nr_php_observer_fcall_end_late(zend_execute_data* execute_data, bool create_metric, nrtime_t txn_start_time);
void nr_php_observer_fcall_end_create_metric(zend_execute_data* execute_data,
zval* func_return_value);
zval* func_return_value);
void nr_php_observer_fcall_end_exception_handler(zend_execute_data* execute_data,
zval* func_return_value);
#endif /* PHP 8.2+ */
#endif /* PHP8+ */

Expand Down