Skip to content
22 changes: 22 additions & 0 deletions agent/fw_laravel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,19 @@ NR_PHP_WRAPPER(nr_laravel_horizon_end_txn) {
}
NR_PHP_WRAPPER_END

/*
* End transaction for idle laravel queue workers and then start
* a new transaction.
*/
NR_PHP_WRAPPER(nr_laravel_queue_restart_transaction) {
NR_UNUSED_SPECIALFN;
(void)wraprec;

nr_php_txn_end(1, 0 TSRMLS_CC);
nr_php_txn_begin(NULL, NULL TSRMLS_CC);
}
NR_PHP_WRAPPER_END

void nr_laravel_enable(TSRMLS_D) {
/*
* We set the path to 'unknown' to prevent having to name routing errors.
Expand Down Expand Up @@ -1259,6 +1272,15 @@ void nr_laravel_enable(TSRMLS_D) {
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("Laravel\\Horizon\\Console\\SupervisorCommand::handle"),
nr_laravel_horizon_end_txn, NULL, NULL);

/*
* The following function has been added to ensure idle laravel queue workers
* are properly handled by ending the current transaction and starting a new
* one.
*/
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("Illuminate\\Queue\\Worker::daemonShouldRun"),
nr_laravel_queue_restart_transaction, NULL, NULL);
#else
nr_php_wrap_user_function(NR_PSTR("Symfony\\Component\\Console\\Application::doRun"),
nr_laravel_console_application_dorun TSRMLS_CC);
Expand Down