Skip to content

Commit

Permalink
Normalize the queue name
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Jun 18, 2024
1 parent c18135d commit a4d88f6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Sentry/Laravel/Features/QueueIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public function onBoot(Dispatcher $events): void
->setData([
'messaging.system' => 'laravel',
'messaging.message.id' => $payload['uuid'] ?? null,
// Jobs pushed onto the Redis driver are formatted as queues:<queue>
'messaging.destination.name' => Str::after($queue ?? '', 'queues:'),
'messaging.destination.name' => $this->normalizeQueueName($queue),
'messaging.destination.connection' => $connection,
])
->setDescription($queue);
Expand Down Expand Up @@ -190,7 +189,7 @@ public function handleJobProcessingQueueEvent(JobProcessing $event): void
$job = [
'messaging.system' => 'laravel',

'messaging.destination.name' => $event->job->getQueue(),
'messaging.destination.name' => $this->normalizeQueueName($event->job->getQueue()),
'messaging.destination.connection' => $event->connectionName,

'messaging.message.id' => $jobPayload['uuid'] ?? null,
Expand Down Expand Up @@ -241,6 +240,21 @@ private function finishJobWithStatus(SpanStatus $status): void
}
}

private function normalizeQueueName(?string $queue): string
{
if ($queue === null) {
return '';
}

// SQS queues are sometimes formatted like: https://sqs.<region>.amazonaws.com/<id>/<queue_name>
if (filter_var($queue, FILTER_VALIDATE_URL) !== false) {
return Str::afterLast($queue, '/');
}

// Jobs pushed onto the Redis driver are formatted as queues:<queue>
return Str::after($queue, 'queues:');
}

protected function pushScope(): void
{
$this->pushScopeTrait();
Expand Down

0 comments on commit a4d88f6

Please sign in to comment.