Skip to content

Commit cd4e412

Browse files
authored
feat(agent): add supportability metric for laravel horizon and queue (#1132)
This PR does the following: - Wrap `Laravel\Horizon\Console\WorkCommand` to check if Laravel Horizon is being used and if it is, then set `is_horizon_used` global flag to `true`. - Check value of `is_horizon_used` flag which will determine what supportability metric is sent. (`Supportability/library/Laravel/Horizon/used` or `Supportability/library/Laravel/Queue/used`)
1 parent e1738ac commit cd4e412

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

agent/fw_laravel.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,17 @@ NR_PHP_WRAPPER(nr_laravel_queue_restart_transaction) {
12211221
}
12221222
NR_PHP_WRAPPER_END
12231223

1224+
/*
1225+
* Set global flag that checks if Laravel Horizon is being used to true.
1226+
*/
1227+
NR_PHP_WRAPPER(nr_laravel_horizon_is_used) {
1228+
NR_UNUSED_SPECIALFN;
1229+
(void)wraprec;
1230+
1231+
NR_PHP_PROCESS_GLOBALS(laravel_horizon_worker_used) = true;
1232+
}
1233+
NR_PHP_WRAPPER_END
1234+
12241235
void nr_laravel_enable(TSRMLS_D) {
12251236
/*
12261237
* We set the path to 'unknown' to prevent having to name routing errors.
@@ -1272,7 +1283,12 @@ void nr_laravel_enable(TSRMLS_D) {
12721283
nr_php_wrap_user_function_before_after_clean(
12731284
NR_PSTR("Laravel\\Horizon\\Console\\SupervisorCommand::handle"),
12741285
nr_laravel_horizon_end_txn, NULL, NULL);
1275-
1286+
/*
1287+
* Check if Laravel Horizon is being used.
1288+
*/
1289+
nr_php_wrap_user_function_before_after_clean(
1290+
NR_PSTR("Laravel\\Horizon\\Console\\WorkCommand::handle"),
1291+
nr_laravel_horizon_is_used, NULL, NULL);
12761292
/*
12771293
* The following function has been added to ensure idle laravel queue workers
12781294
* are properly handled by ending the current transaction and starting a new

agent/fw_laravel_queue.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "php_api_distributed_trace.h"
77
#include "php_call.h"
88
#include "php_error.h"
9+
#include "php_globals.h"
910
#include "php_hash.h"
1011
#include "php_user_instrument.h"
1112
#include "php_wrapper.h"
@@ -294,6 +295,13 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_raiseBeforeJobEvent_before) {
294295
nr_txn_set_path("Laravel", NRPRG(txn), txn_name, NR_PATH_TYPE_CUSTOM,
295296
NR_OK_TO_OVERWRITE);
296297

298+
if (NR_PHP_PROCESS_GLOBALS(laravel_horizon_worker_used)) {
299+
nrm_force_add(NRPRG(txn) ? NRPRG(txn)->unscoped_metrics : 0,
300+
"Supportability/library/Laravel/Horizon/used", 0);
301+
} else {
302+
nrm_force_add(NRPRG(txn) ? NRPRG(txn)->unscoped_metrics : 0,
303+
"Supportability/library/Laravel/Queue/used", 0);
304+
}
297305
nr_free(txn_name);
298306
nr_php_arg_release(&job);
299307
NR_PHP_WRAPPER_CALL;

agent/php_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct _nrphpglobals_t {
8080
enabled */
8181
nr_composer_api_status_t composer_api_status; /* Composer API's status */
8282
char* docker_id; /* 64 byte hex docker ID parsed from /proc/self/mountinfo */
83+
bool laravel_horizon_worker_used; /* Set to true if Laravel Horizon is used */
8384

8485
/* Original PHP callback pointer contents */
8586
nrphperrfn_t orig_error_cb;

0 commit comments

Comments
 (0)