Skip to content

Commit

Permalink
Add support for the Queue Module (#902)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Bouma <alex@bouma.me>
  • Loading branch information
cleptric and stayallive committed Jun 4, 2024
1 parent 039fd4e commit cb4311f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Sentry/Laravel/Features/QueueIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class QueueIntegration extends Feature

private const QUEUE_PAYLOAD_BAGGAGE_DATA = 'sentry_baggage_data';
private const QUEUE_PAYLOAD_TRACE_PARENT_DATA = 'sentry_trace_parent_data';
private const QUEUE_PAYLOAD_PUBLISH_TIME = 'sentry_publish_time';

public function isApplicable(): bool
{
Expand Down Expand Up @@ -78,6 +79,7 @@ public function onBoot(Dispatcher $events): void
if ($payload !== null) {
$payload[self::QUEUE_PAYLOAD_BAGGAGE_DATA] = getBaggage();
$payload[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] = getTraceparent();
$payload[self::QUEUE_PAYLOAD_PUBLISH_TIME] = microtime(true);
}

return $payload;
Expand All @@ -103,9 +105,6 @@ public function handleJobQueueingEvent(JobQueueing $event): void
}

$currentSpan
->setData([
'messaging.laravel.job' => $jobName,
])
->setDescription($jobName);
}

Expand Down Expand Up @@ -181,12 +180,22 @@ public function handleJobProcessingQueueEvent(JobProcessing $event): void

$resolvedJobName = $event->job->resolveName();

$receiveLatency = null;
if ($event->job->payload()[self::QUEUE_PAYLOAD_PUBLISH_TIME] !== null) {
$receiveLatency = microtime(true) - $event->job->payload()[self::QUEUE_PAYLOAD_PUBLISH_TIME];
}

$job = [
'job' => $event->job->getName(),
'queue' => $event->job->getQueue(),
'resolved' => $resolvedJobName,
'attempts' => $event->job->attempts(),
'connection' => $event->connectionName,
'messaging.system' => 'laravel',

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

'messaging.message.id' => (string) $event->job->getJobId(),
'messaging.message.envelope.size' => strlen($event->job->getRawBody()),
'messaging.message.body.size' => strlen(json_encode($event->job->payload()['data'])),
'messaging.message.retry.count' => $event->job->attempts(),
'messaging.message.receive.latency' => $receiveLatency,
];

if ($context instanceof TransactionContext) {
Expand Down

0 comments on commit cb4311f

Please sign in to comment.