@@ -247,9 +247,9 @@ static char* nr_laravel_queue_job_txn_name(zval* job TSRMLS_DC) {
247
247
*/
248
248
NR_PHP_WRAPPER (nr_laravel_queue_syncqueue_executeJob_before ) {
249
249
zval * job = NULL ;
250
+ nr_segment_t * segment = NULL ;
250
251
251
252
NR_UNUSED_SPECIALFN ;
252
- (void )wraprec ;
253
253
254
254
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK (NR_FW_LARAVEL );
255
255
@@ -275,6 +275,16 @@ NR_PHP_WRAPPER(nr_laravel_queue_syncqueue_executeJob_before) {
275
275
if (NR_SUCCESS == nr_php_txn_begin (NULL , NULL )) {
276
276
nr_txn_set_as_background_job (NRPRG (txn ), "Laravel job" );
277
277
278
+ segment = nr_txn_get_current_segment (NRPRG (txn ), NULL );
279
+ /*
280
+ * Transfer the old wraprec to the newly created segment inside the brand
281
+ * new txn so that the agent will be able to call any _after or _clean
282
+ * callbacks.
283
+ */
284
+ if (NULL != segment ) {
285
+ segment -> wraprec = wraprec ;
286
+ }
287
+
278
288
if (NULL == txn_name ) {
279
289
txn_name = nr_strdup ("unknown" );
280
290
}
@@ -302,17 +312,16 @@ NR_PHP_WRAPPER_END
302
312
*/
303
313
NR_PHP_WRAPPER (nr_laravel_queue_worker_process_before ) {
304
314
zval * job = NULL ;
315
+ nr_segment_t * segment = NULL ;
305
316
306
317
NR_UNUSED_SPECIALFN ;
307
- (void )wraprec ;
308
318
309
319
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK (NR_FW_LARAVEL );
310
320
311
321
/*
312
322
* End the current txn to prepare for the Job txn.
313
323
*/
314
324
nr_php_txn_end (1 , 0 TSRMLS_CC );
315
-
316
325
/*
317
326
* Job is the second parameter.
318
327
*/
@@ -327,7 +336,15 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_process_before) {
327
336
328
337
if (NR_SUCCESS == nr_php_txn_begin (NULL , NULL )) {
329
338
nr_txn_set_as_background_job (NRPRG (txn ), "Laravel job" );
330
-
339
+ segment = nr_txn_get_current_segment (NRPRG (txn ), NULL );
340
+ /*
341
+ * Transfer the old wraprec to the newly created segment inside the brand
342
+ * new txn so that the agent will be able to call any _after or _clean
343
+ * callbacks.
344
+ */
345
+ if (NULL != segment ) {
346
+ segment -> wraprec = wraprec ;
347
+ }
331
348
if (NULL == txn_name ) {
332
349
txn_name = nr_strdup ("unknown" );
333
350
}
@@ -337,6 +354,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_process_before) {
337
354
nr_txn_set_path ("Laravel" , NRPRG (txn ), txn_name , NR_PATH_TYPE_CUSTOM ,
338
355
NR_OK_TO_OVERWRITE );
339
356
}
357
+
340
358
nr_free (txn_name );
341
359
nr_php_arg_release (& job );
342
360
NR_PHP_WRAPPER_CALL ;
@@ -352,7 +370,6 @@ NR_PHP_WRAPPER_END
352
370
NR_PHP_WRAPPER (nr_laravel_queue_worker_after ) {
353
371
NR_UNUSED_SPECIALFN ;
354
372
(void )wraprec ;
355
-
356
373
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK (NR_FW_LARAVEL );
357
374
358
375
/*
@@ -861,11 +878,17 @@ void nr_laravel_queue_enable(TSRMLS_D) {
861
878
/*
862
879
* Here's the problem: we want to record individual transactions for each job
863
880
* that is executed, but don't want to record a transaction for the actual
864
- * queue:work command, since it spends most of its time sleeping.
881
+ * queue:work command, since it spends most of its time sleeping. The naive
882
+ * approach would be to end the transaction immediately and instrument
883
+ * Worker::process(). The issue with that is that instrumentation hooks
884
+ * aren't executed if we're not actually in a transaction.
865
885
*
866
- * We use the process and executeJob functions which we
867
- * can use to name the Laravel Job and capture the true time that the job
868
- * took.
886
+ * So instead, what we'll do is to keep recording, but ensure that we ignore
887
+ * the transaction before and after
888
+ * Illuminate\\Queue\\Worker::process
889
+ * Illuminate\\Queue\\SyncQueue::executeJob
890
+ * This ensures that we instrument the entirety of the job (including any
891
+ * handle/failed functions)
869
892
*/
870
893
871
894
/*
@@ -893,9 +916,8 @@ void nr_laravel_queue_enable(TSRMLS_D) {
893
916
* aren't executed if we're not actually in a transaction.
894
917
*
895
918
* So instead, what we'll do is to keep recording, but ensure that we ignore
896
- * the transaction before and after
897
- * Illuminate\\Queue\\Worker::process
898
- * Illuminate\\Queue\\SyncQueue::executeJob
919
+ * the transaction after WorkCommand::handle() has finished executing, at
920
+ * which point no more jobs can be run.
899
921
*/
900
922
901
923
nr_php_wrap_user_function (
0 commit comments