Skip to content

Commit 9c04484

Browse files
ZNeumannlavarou
authored andcommitted
add exception handler fcall_end
1 parent 0d7062b commit 9c04484

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

agent/php_execute.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO) {
20772077
bool create_metric = false;
20782078
nr_php_execute_metadata_t metadata = {0};
20792079
#else
2080-
static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, bool end_segment) {
2080+
static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, bool end_segment, bool is_exception_handler) {
20812081
#endif
20822082
nr_segment_t* segment = NULL;
20832083
nrtime_t txn_start_time = 0;
@@ -2116,8 +2116,10 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, boo
21162116

21172117
#if ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO
21182118
wraprec = segment->wraprec;
2119-
21202119
if (segment->is_exception_handler) {
2120+
#else
2121+
if (is_exception_handler) {
2122+
#endif
21212123
/*
21222124
* After running the exception handler segment, create an error from
21232125
* the exception it handled, and save the error in the transaction.
@@ -2131,9 +2133,10 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric, boo
21312133
nr_php_error_record_exception(
21322134
NRPRG(txn), exception, nr_php_error_get_priority(E_ERROR), false,
21332135
"Uncaught exception ", &NRPRG(exception_filters) TSRMLS_CC);
2136+
#if ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO
21342137
} else if (NULL == nr_php_get_return_value(NR_EXECUTE_ORIG_ARGS)) {
21352138
#else
2136-
if (NULL == func_return_value) {
2139+
} else if (NULL == func_return_value) {
21372140
#endif
21382141
/*
21392142
* Having no return value (and not being an exception handler) indicates
@@ -2273,7 +2276,8 @@ void nr_php_observer_fcall_begin(zend_execute_data* execute_data) {
22732276
static void nr_php_observer_fcall_end_common(zend_execute_data* execute_data,
22742277
zval* func_return_value,
22752278
bool create_metric,
2276-
bool end_segment) {
2279+
bool end_segment,
2280+
bool is_exception_handler) {
22772281
#else
22782282
void nr_php_observer_fcall_end(zend_execute_data* execute_data,
22792283
zval* func_return_value) {
@@ -2304,7 +2308,7 @@ void nr_php_observer_fcall_end(zend_execute_data* execute_data,
23042308
}
23052309

23062310
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2307-
nr_php_instrument_func_end(NR_EXECUTE_ORIG_ARGS, create_metric, end_segment);
2311+
nr_php_instrument_func_end(NR_EXECUTE_ORIG_ARGS, create_metric, end_segment, is_exception_handler);
23082312
#else
23092313
nr_php_instrument_func_end(NR_EXECUTE_ORIG_ARGS);
23102314
#endif
@@ -2324,15 +2328,19 @@ void nr_php_observer_fcall_begin_instrumented(zend_execute_data* execute_data) {
23242328
}
23252329
void nr_php_observer_fcall_end(zend_execute_data* execute_data,
23262330
zval* func_return_value) {
2327-
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, true);
2331+
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, true, false);
23282332
}
23292333
void nr_php_observer_fcall_end_create_metric(zend_execute_data* execute_data,
23302334
zval* func_return_value) {
2331-
nr_php_observer_fcall_end_common(execute_data, func_return_value, true, true);
2335+
nr_php_observer_fcall_end_common(execute_data, func_return_value, true, true, false);
23322336
}
23332337
void nr_php_observer_fcall_end_keep_segment(zend_execute_data* execute_data,
23342338
zval* func_return_value) {
2335-
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, false);
2339+
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, false, false);
2340+
}
2341+
void nr_php_observer_fcall_end_exception_handler(zend_execute_data* execute_data,
2342+
zval* func_return_value) {
2343+
nr_php_observer_fcall_end_common(execute_data, func_return_value, false, true, true);
23362344
}
23372345

23382346
// These empty functions (rather than NULL) are used to know if instrumentation

agent/php_observer.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ static zend_observer_fcall_handlers nr_php_fcall_register_handlers(
121121
nr_php_observer_fcall_begin_instrumented;
122122
handlers.end = wraprec->special_instrumentation ?
123123
(zend_observer_fcall_end_handler)wraprec->special_instrumentation :
124-
wraprec->create_metric ?
125-
nr_php_observer_fcall_end_create_metric :
126-
nr_php_observer_fcall_end;
124+
wraprec->is_exception_handler ?
125+
nr_php_observer_fcall_end_exception_handler :
126+
wraprec->create_metric ?
127+
nr_php_observer_fcall_end_create_metric :
128+
nr_php_observer_fcall_end;
127129
return handlers;
128130
}
129131

@@ -152,7 +154,9 @@ void nr_php_observer_overwrite_handlers(zend_function* func, nruserfn_t* wraprec
152154
nr_php_observer_empty_fcall_end)) {
153155
zend_observer_add_end_handler(func, wraprec->special_instrumentation ?
154156
(zend_observer_fcall_end_handler)wraprec->special_instrumentation :
155-
nr_php_observer_fcall_end);
157+
wraprec->is_exception_handler ?
158+
nr_php_observer_fcall_end_exception_handler :
159+
nr_php_observer_fcall_end);
156160
}
157161
}
158162
}

agent/php_observer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ void nr_php_observer_empty_fcall_end(zend_execute_data* execute_data,
8888
zval* func_return_value);
8989
void nr_php_observer_fcall_begin_late(zend_execute_data* execute_data, nrtime_t txn_start_time);
9090
void nr_php_observer_fcall_end_keep_segment(zend_execute_data* execute_data,
91-
zval* func_return_value);
91+
zval* func_return_value);
9292
void nr_php_observer_fcall_end_late(zend_execute_data* execute_data, bool create_metric, nrtime_t txn_start_time);
9393
void nr_php_observer_fcall_end_create_metric(zend_execute_data* execute_data,
94-
zval* func_return_value);
94+
zval* func_return_value);
95+
void nr_php_observer_fcall_end_exception_handler(zend_execute_data* execute_data,
96+
zval* func_return_value);
9597
#endif /* PHP 8.2+ */
9698
#endif /* PHP8+ */
9799

0 commit comments

Comments
 (0)