@@ -254,21 +254,21 @@ static void nr_php_wrap_zend_function(zend_function* func,
254254 }
255255}
256256
257- static zend_function * nr_php_wrap_user_function_internal (nruserfn_t * wraprec TSRMLS_DC ) {
257+ static void nr_php_wrap_user_function_internal (nruserfn_t * wraprec TSRMLS_DC ) {
258258 zend_function * orig_func = 0 ;
259259
260260 if (0 == NR_PHP_PROCESS_GLOBALS (done_instrumentation )) {
261- return NULL ;
261+ return ;
262262 }
263263
264264 if (wraprec -> is_wrapped ) {
265- return NULL ;
265+ return ;
266266 }
267267
268268#if ZEND_MODULE_API_NO < ZEND_8_0_X_API_NO \
269269 && defined OVERWRITE_ZEND_EXECUTE_DATA /* PHP8+ */
270270 if (nrunlikely (-1 == NR_PHP_PROCESS_GLOBALS (zend_offset ))) {
271- return NULL ;
271+ return ;
272272 }
273273#endif
274274 if (0 == wraprec -> classname ) {
@@ -282,8 +282,9 @@ static zend_function* nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSR
282282
283283 if (NULL == orig_func ) {
284284 /* It could be in a file not yet loaded, no reason to log anything. */
285- return NULL ;
285+ return ;
286286 }
287+ wraprec -> func = orig_func ;
287288
288289 if (ZEND_USER_FUNCTION != orig_func -> type ) {
289290 nrl_verbosedebug (NRL_INSTRUMENT , "%s%s%s is not a user function" ,
@@ -295,10 +296,9 @@ static zend_function* nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSR
295296 * logs with this message.
296297 */
297298 wraprec -> is_disabled = 1 ;
298- return NULL ;
299+ return ;
299300 }
300301 nr_php_wrap_zend_function (orig_func , wraprec TSRMLS_CC );
301- return orig_func ;
302302}
303303
304304static nruserfn_t * nr_php_user_wraprec_create (void ) {
@@ -429,6 +429,10 @@ nruserfn_t* nr_php_add_custom_tracer_callable(zend_function* func TSRMLS_DC) {
429429 nrl_verbosedebug (NRL_INSTRUMENT , "reusing custom wrapper for callable '%s'" ,
430430 name );
431431 nr_free (name );
432+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
433+ nr_php_observer_remove_begin_handler (func , wraprec );
434+ nr_php_observer_remove_end_handler (func , wraprec );
435+ #endif
432436 return wraprec ;
433437 }
434438
@@ -442,6 +446,10 @@ nruserfn_t* nr_php_add_custom_tracer_callable(zend_function* func TSRMLS_DC) {
442446#if ZEND_MODULE_API_NO < ZEND_7_4_X_API_NO
443447 nr_php_add_custom_tracer_common (wraprec );
444448#endif
449+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
450+ nr_php_observer_remove_begin_handler (func , NULL );
451+ nr_php_observer_remove_end_handler (func , NULL );
452+ #endif
445453
446454 return wraprec ;
447455}
@@ -450,9 +458,6 @@ nruserfn_t* nr_php_add_custom_tracer_named(const char* namestr,
450458 size_t namestrlen ) {
451459 nruserfn_t * wraprec ;
452460 nruserfn_t * p ;
453- #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
454- zend_function * orig_func ;
455- #endif
456461
457462 wraprec = nr_php_user_wraprec_create_named (namestr , namestrlen );
458463 if (0 == wraprec ) {
@@ -472,6 +477,10 @@ nruserfn_t* nr_php_add_custom_tracer_named(const char* namestr,
472477
473478 nr_php_user_wraprec_destroy (& wraprec );
474479 nr_php_wrap_user_function_internal (p TSRMLS_CC );
480+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
481+ nr_php_observer_remove_begin_handler (p -> func , wraprec );
482+ nr_php_observer_remove_end_handler (p -> func , wraprec );
483+ #endif
475484 return p ; /* return the wraprec we are duplicating */
476485 }
477486 p = p -> next ;
@@ -482,18 +491,15 @@ nruserfn_t* nr_php_add_custom_tracer_named(const char* namestr,
482491 NRP_PHP (wraprec -> classname ),
483492 (0 == wraprec -> classname ) ? "" : "::" , NRP_PHP (wraprec -> funcname ));
484493
485- #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
486- orig_func = nr_php_wrap_user_function_internal (wraprec TSRMLS_CC );
487- #else
488494 nr_php_wrap_user_function_internal (wraprec TSRMLS_CC );
489- #endif
490495 /* non-transient wraprecs are added to both the hashmap and linked list.
491496 * At request shutdown, the hashmap will free transients, but leave
492497 * non-transients to be freed when the linked list is disposed of which is at
493498 * module shutdown */
494499 nr_php_add_custom_tracer_common (wraprec );
495500#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
496- nr_php_observer_overwrite_handlers (orig_func , wraprec );
501+ nr_php_observer_remove_begin_handler (wraprec -> func , NULL );
502+ nr_php_observer_remove_end_handler (wraprec -> func , NULL );
497503#endif
498504
499505 return wraprec ; /* return the new wraprec */
@@ -579,6 +585,10 @@ void nr_php_add_transaction_naming_function(const char* namestr,
579585
580586 if (NULL != wraprec ) {
581587 wraprec -> is_names_wt_simple = 1 ;
588+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
589+ nr_php_observer_add_begin_handler (wraprec -> func , wraprec );
590+ nr_php_observer_add_end_handler (wraprec -> func , wraprec );
591+ #endif
582592 }
583593}
584594
@@ -588,6 +598,10 @@ void nr_php_add_custom_tracer(const char* namestr, int namestrlen TSRMLS_DC) {
588598 if (NULL != wraprec ) {
589599 wraprec -> create_metric = 1 ;
590600 wraprec -> is_user_added = 1 ;
601+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
602+ nr_php_observer_add_begin_handler (wraprec -> func , wraprec );
603+ nr_php_observer_add_end_handler (wraprec -> func , wraprec );
604+ #endif
591605 }
592606}
593607
@@ -596,6 +610,10 @@ void nr_php_add_exception_function(zend_function* func TSRMLS_DC) {
596610
597611 if (wraprec ) {
598612 wraprec -> is_exception_handler = 1 ;
613+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
614+ nr_php_observer_add_begin_handler (func , wraprec );
615+ nr_php_observer_add_end_handler (func , wraprec );
616+ #endif
599617 }
600618}
601619
@@ -651,6 +669,10 @@ void nr_php_user_function_add_declared_callback(const char* namestr,
651669 if (wraprec -> is_wrapped && callback ) {
652670 (callback )(TSRMLS_C );
653671 }
672+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
673+ nr_php_observer_add_begin_handler (wraprec -> func , wraprec );
674+ nr_php_observer_add_end_handler (wraprec -> func , wraprec );
675+ #endif
654676 }
655677}
656678
0 commit comments