Skip to content

Commit

Permalink
fix: Prevent Laravel Queue hooks from stacking up (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM authored Oct 18, 2024
1 parent ed256f3 commit 8f7175e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/DDTrace/Integrations/LaravelQueue/LaravelQueueIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ function ($worker, $scope, $args, $retval) use ($integration) {
]
);

hook_method(
'Illuminate\Queue\Jobs\Job',
'fire',
function ($job, $scope, $args) use ($integration) {
$payload = $job->payload();
install_hook(
'Illuminate\Queue\Jobs\Job::fire',
function (HookData $fireHook) use ($integration) {
/** @var \Illuminate\Queue\Jobs\Job $this */
$payload = $this->payload();
list($class, $method) = JobName::parse($payload['job']);

if ($class == 'Illuminate\\Queue\\CallQueuedHandler') {
$class = $payload['data']['commandName'];
$method = 'handle';
}

install_hook(
$fireHook->data['id'] = install_hook(
"$class::$method",
function (HookData $hook) use ($integration, $class, $method) {
function (HookData $hook) use ($integration, $class, $method, $fireHook) {
$span = $hook->span();
$span->name = 'laravel.queue.action';
$span->type = 'queue';
Expand All @@ -191,6 +191,9 @@ function (HookData $hook) use ($integration, $class, $method) {
remove_hook($hook->id);
}
);
},
function (HookData $fireHook) {
remove_hook($fireHook->data['id']);
}
);

Expand Down

0 comments on commit 8f7175e

Please sign in to comment.