Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue integration fixes #904

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Sentry/Laravel/Features/QueueIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function onBoot(Dispatcher $events): void
->setOp(self::QUEUE_SPAN_OP_QUEUE_PUBLISH)
->setData([
'messaging.system' => 'laravel',
'messaging.message.id' => $payload['uuid'] ?? null,
'messaging.destination.name' => $queue,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is prepended with "queue:" to something like: queues:queue-name

We need to "fix" this because otherwise the published are on the wrong destination.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out... only the Redis driver does this. We could argue Laravel should fix this but let's also fix it ourselfs 😄

'messaging.destination.connection' => $connection,
])
Expand Down Expand Up @@ -164,9 +165,11 @@ public function handleJobProcessingQueueEvent(JobProcessing $event): void
return;
}

$jobPayload = $event->job->payload();

if ($parentSpan === null) {
$baggage = $event->job->payload()[self::QUEUE_PAYLOAD_BAGGAGE_DATA] ?? null;
$traceParent = $event->job->payload()[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] ?? null;
$baggage = $jobPayload[self::QUEUE_PAYLOAD_BAGGAGE_DATA] ?? null;
$traceParent = $jobPayload[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] ?? null;

$context = continueTrace($traceParent ?? '', $baggage ?? '');

Expand All @@ -180,22 +183,19 @@ 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];
}
$jobPublishedAt = $jobPayload[self::QUEUE_PAYLOAD_PUBLISH_TIME] ?? null;

$job = [
'messaging.system' => 'laravel',

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

'messaging.message.id' => $jobPayload['uuid'] ?? $event->job->getJobId(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep the string cast for $event->job->getJobId().

Copy link
Collaborator Author

@stayallive stayallive Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's documented as returning a string? When doesn't it do that?

Maybe we should just rely on $jobPayload['uuid'] anyway otherwise they will never match. Laravel should always add a ID to the job payload. Not sure if it's possible to not have one.

'messaging.message.envelope.size' => strlen($event->job->getRawBody()),
'messaging.message.body.size' => strlen(json_encode($event->job->payload()['data'])),
'messaging.message.body.size' => strlen(json_encode($jobPayload['data'] ?? [])),
'messaging.message.retry.count' => $event->job->attempts(),
'messaging.message.receive.latency' => $receiveLatency,
'messaging.message.receive.latency' => $jobPublishedAt !== null ? microtime(true) - $jobPublishedAt : null,
];

if ($context instanceof TransactionContext) {
Expand Down
Loading