@@ -2047,16 +2047,40 @@ void nr_php_observer_fcall_begin_late(zend_execute_data* execute_data, nrtime_t
2047
2047
}
2048
2048
#endif
2049
2049
2050
+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2051
+ void nr_php_observer_fcall_end_late (zend_execute_data * execute_data , bool create_metric , nrtime_t txn_start_time ) {
2052
+ nr_segment_t * segment ;
2053
+ nr_php_execute_metadata_t metadata = {0 };
2054
+ if (nrunlikely (nr_txn_start_time (NRPRG (txn )) != txn_start_time )) {
2055
+ nrl_verbosedebug (NRL_AGENT ,
2056
+ "%s txn ended and/or started while in a wrapped function" ,
2057
+ __func__ );
2058
+
2059
+ return ;
2060
+ }
2061
+
2062
+ /*
2063
+ * Reassign segment to the current segment, as some before/after wraprecs
2064
+ * start and then stop a segment. If that happened, we want to ensure we
2065
+ * get the now-current segment
2066
+ */
2067
+ segment = nr_txn_get_current_segment (NRPRG (txn ), NULL );
2068
+ nr_php_execute_metadata_init (& metadata , NR_OP_ARRAY );
2069
+ nr_php_execute_segment_end (segment , & metadata , create_metric );
2070
+ nr_php_execute_metadata_release (& metadata );
2071
+ }
2072
+ #endif
2073
+
2050
2074
#if ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO
2051
2075
static void nr_php_instrument_func_end (NR_EXECUTE_PROTO ) {
2052
2076
int zcaught = 0 ;
2053
2077
nruserfn_t * wraprec = NULL ;
2054
2078
bool create_metric = false;
2079
+ nr_php_execute_metadata_t metadata = {0 };
2055
2080
#else
2056
- static void nr_php_instrument_func_end (NR_EXECUTE_PROTO , bool create_metric ) {
2081
+ static void nr_php_instrument_func_end (NR_EXECUTE_PROTO , bool create_metric , bool end_segment ) {
2057
2082
#endif
2058
2083
nr_segment_t * segment = NULL ;
2059
- nr_php_execute_metadata_t metadata = {0 };
2060
2084
nrtime_t txn_start_time = 0 ;
2061
2085
2062
2086
if (NULL == NRPRG (txn )) {
@@ -2159,7 +2183,6 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric) {
2159
2183
nr_segment_discard (& segment );
2160
2184
return ;
2161
2185
}
2162
- #endif
2163
2186
/*
2164
2187
* During nr_zend_call_orig_execute_special, the transaction may have been
2165
2188
* ended and/or a new transaction may have started. To detect this, we
@@ -2187,6 +2210,11 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric) {
2187
2210
nr_php_execute_metadata_init (& metadata , NR_OP_ARRAY );
2188
2211
nr_php_execute_segment_end (segment , & metadata , create_metric );
2189
2212
nr_php_execute_metadata_release (& metadata );
2213
+ #else
2214
+ if (end_segment ) {
2215
+ nr_php_observer_fcall_end_late (execute_data , create_metric , txn_start_time );
2216
+ }
2217
+ #endif
2190
2218
return ;
2191
2219
}
2192
2220
@@ -2307,7 +2335,7 @@ void nr_php_observer_fcall_end(zend_execute_data* execute_data,
2307
2335
}
2308
2336
2309
2337
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2310
- nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , false);
2338
+ nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , false, true );
2311
2339
#else
2312
2340
nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS );
2313
2341
#endif
@@ -2323,6 +2351,41 @@ void nr_php_observer_fcall_end(zend_execute_data* execute_data,
2323
2351
// has been added This is needed because the process for adding instrumentation
2324
2352
// with a transient wrapper differs depending on if the function has been
2325
2353
// previously called. These will only be used when tt_detail is 0.
2354
+ void nr_php_observer_fcall_end_keep_segment (zend_execute_data * execute_data ,
2355
+ zval * func_return_value ) {
2356
+ /*
2357
+ * Instrument the function.
2358
+ * This and any other needed helper functions will replace:
2359
+ * nr_php_execute_enabled
2360
+ * nr_php_execute
2361
+ * nr_php_execute_show
2362
+ */
2363
+ if (nrunlikely (NULL == execute_data )) {
2364
+ return ;
2365
+ }
2366
+ //if (execute_data->func && execute_data->func->common.function_name) {
2367
+ // printf("END %s\n", ZSTR_VAL(execute_data->func->common.function_name));
2368
+ //}
2369
+
2370
+ if (nrlikely (1 == nr_php_recording ())) {
2371
+ int show_executes_return
2372
+ = NR_PHP_PROCESS_GLOBALS (special_flags ).show_execute_returns ;
2373
+
2374
+ if (nrunlikely (show_executes_return )) {
2375
+ nrl_verbosedebug (NRL_AGENT ,
2376
+ "Stack depth: %d before OAPI function exiting via %s" ,
2377
+ NRPRG (php_cur_stack_depth ), __func__ );
2378
+ nr_php_show_exec_return (NR_EXECUTE_ORIG_ARGS TSRMLS_CC );
2379
+ }
2380
+
2381
+ nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , false, false);
2382
+ }
2383
+
2384
+ NRPRG (php_cur_stack_depth ) -= 1 ;
2385
+
2386
+ return ;
2387
+ }
2388
+
2326
2389
void nr_php_observer_empty_fcall_begin (zend_execute_data * execute_data ) {
2327
2390
(void )execute_data ;
2328
2391
}
@@ -2360,7 +2423,7 @@ void nr_php_observer_fcall_end_create_metric(zend_execute_data* execute_data,
2360
2423
nr_php_show_exec_return (NR_EXECUTE_ORIG_ARGS TSRMLS_CC );
2361
2424
}
2362
2425
2363
- nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , true);
2426
+ nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , true, true );
2364
2427
}
2365
2428
2366
2429
NRPRG (php_cur_stack_depth ) -= 1 ;
0 commit comments