@@ -2039,16 +2039,40 @@ void nr_php_observer_fcall_begin_late(zend_execute_data* execute_data, nrtime_t
2039
2039
}
2040
2040
#endif
2041
2041
2042
+ #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2043
+ void nr_php_observer_fcall_end_late (zend_execute_data * execute_data , bool create_metric , nrtime_t txn_start_time ) {
2044
+ nr_segment_t * segment ;
2045
+ nr_php_execute_metadata_t metadata = {0 };
2046
+ if (nrunlikely (nr_txn_start_time (NRPRG (txn )) != txn_start_time )) {
2047
+ nrl_verbosedebug (NRL_AGENT ,
2048
+ "%s txn ended and/or started while in a wrapped function" ,
2049
+ __func__ );
2050
+
2051
+ return ;
2052
+ }
2053
+
2054
+ /*
2055
+ * Reassign segment to the current segment, as some before/after wraprecs
2056
+ * start and then stop a segment. If that happened, we want to ensure we
2057
+ * get the now-current segment
2058
+ */
2059
+ segment = nr_txn_get_current_segment (NRPRG (txn ), NULL );
2060
+ nr_php_execute_metadata_init (& metadata , NR_OP_ARRAY );
2061
+ nr_php_execute_segment_end (segment , & metadata , create_metric );
2062
+ nr_php_execute_metadata_release (& metadata );
2063
+ }
2064
+ #endif
2065
+
2042
2066
#if ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO
2043
2067
static void nr_php_instrument_func_end (NR_EXECUTE_PROTO ) {
2044
2068
int zcaught = 0 ;
2045
2069
nruserfn_t * wraprec = NULL ;
2046
2070
bool create_metric = false;
2071
+ nr_php_execute_metadata_t metadata = {0 };
2047
2072
#else
2048
- static void nr_php_instrument_func_end (NR_EXECUTE_PROTO , bool create_metric ) {
2073
+ static void nr_php_instrument_func_end (NR_EXECUTE_PROTO , bool create_metric , bool end_segment ) {
2049
2074
#endif
2050
2075
nr_segment_t * segment = NULL ;
2051
- nr_php_execute_metadata_t metadata = {0 };
2052
2076
nrtime_t txn_start_time = 0 ;
2053
2077
2054
2078
if (NULL == NRPRG (txn )) {
@@ -2151,7 +2175,6 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric) {
2151
2175
nr_segment_discard (& segment );
2152
2176
return ;
2153
2177
}
2154
- #endif
2155
2178
/*
2156
2179
* During nr_zend_call_orig_execute_special, the transaction may have been
2157
2180
* ended and/or a new transaction may have started. To detect this, we
@@ -2179,6 +2202,11 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO, bool create_metric) {
2179
2202
nr_php_execute_metadata_init (& metadata , NR_OP_ARRAY );
2180
2203
nr_php_execute_segment_end (segment , & metadata , create_metric );
2181
2204
nr_php_execute_metadata_release (& metadata );
2205
+ #else
2206
+ if (end_segment ) {
2207
+ nr_php_observer_fcall_end_late (execute_data , create_metric , txn_start_time );
2208
+ }
2209
+ #endif
2182
2210
return ;
2183
2211
}
2184
2212
@@ -2299,7 +2327,7 @@ void nr_php_observer_fcall_end(zend_execute_data* execute_data,
2299
2327
}
2300
2328
2301
2329
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2302
- nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , false);
2330
+ nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , false, true );
2303
2331
#else
2304
2332
nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS );
2305
2333
#endif
@@ -2315,6 +2343,41 @@ void nr_php_observer_fcall_end(zend_execute_data* execute_data,
2315
2343
// has been added This is needed because the process for adding instrumentation
2316
2344
// with a transient wrapper differs depending on if the function has been
2317
2345
// previously called. These will only be used when tt_detail is 0.
2346
+ void nr_php_observer_fcall_end_keep_segment (zend_execute_data * execute_data ,
2347
+ zval * func_return_value ) {
2348
+ /*
2349
+ * Instrument the function.
2350
+ * This and any other needed helper functions will replace:
2351
+ * nr_php_execute_enabled
2352
+ * nr_php_execute
2353
+ * nr_php_execute_show
2354
+ */
2355
+ if (nrunlikely (NULL == execute_data )) {
2356
+ return ;
2357
+ }
2358
+ //if (execute_data->func && execute_data->func->common.function_name) {
2359
+ // printf("END %s\n", ZSTR_VAL(execute_data->func->common.function_name));
2360
+ //}
2361
+
2362
+ if (nrlikely (1 == nr_php_recording ())) {
2363
+ int show_executes_return
2364
+ = NR_PHP_PROCESS_GLOBALS (special_flags ).show_execute_returns ;
2365
+
2366
+ if (nrunlikely (show_executes_return )) {
2367
+ nrl_verbosedebug (NRL_AGENT ,
2368
+ "Stack depth: %d before OAPI function exiting via %s" ,
2369
+ NRPRG (php_cur_stack_depth ), __func__ );
2370
+ nr_php_show_exec_return (NR_EXECUTE_ORIG_ARGS TSRMLS_CC );
2371
+ }
2372
+
2373
+ nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , false, false);
2374
+ }
2375
+
2376
+ NRPRG (php_cur_stack_depth ) -= 1 ;
2377
+
2378
+ return ;
2379
+ }
2380
+
2318
2381
void nr_php_observer_empty_fcall_begin (zend_execute_data * execute_data ) {
2319
2382
(void )execute_data ;
2320
2383
}
@@ -2352,7 +2415,7 @@ void nr_php_observer_fcall_end_create_metric(zend_execute_data* execute_data,
2352
2415
nr_php_show_exec_return (NR_EXECUTE_ORIG_ARGS TSRMLS_CC );
2353
2416
}
2354
2417
2355
- nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , true);
2418
+ nr_php_instrument_func_end (NR_EXECUTE_ORIG_ARGS , true, true );
2356
2419
}
2357
2420
2358
2421
NRPRG (php_cur_stack_depth ) -= 1 ;
0 commit comments