getsentry / sentry-docs

Sentry's documentation (and tools to build it)
https://docs.sentry.io
Other
331 stars 1.46k forks source link

Instrument Queues - PHP example #11711

Open rodion-k opened 2 hours ago

rodion-k commented 2 hours ago

SDK

PHP SDK

Description

In the consumer instrumentation example, the $job variable is used before initialization:

$context = \Sentry\continueTrace(
    $job->getMetadata('sentry_trace'), // $job variable is used here
    $job->getMetadata('baggage')
)
    ->setOp('queue.process')
    ->setName('App\Jobs\MyJob');

$transaction = \Sentry\startTransaction($context);

\Sentry\SentrySdk::getCurrentHub()->setSpan($transaction);

$job = Queue::pop(); // but initialization is here

try {
    // Continue job processing...
} catch (\Throwable $e) {
    $transaction->setStatus(\Sentry\Tracing\SpanStatus::internalError());
}

$transaction
    ->setData([
        'messaging.message.id' => $job->getId(),
        'messaging.destination.name' => $job->getQueue(),
        'messaging.message.body.size' => $job->getSize(),
        'messaging.message.receive.latency' =>  microtime(true) - $job->getMetadata('publish_time'),
        'messaging.message.retry.count' => $job->getRetryCount(),
    ])
    ->finish();

https://docs.sentry.io/platforms/php/guides/symfony/tracing/instrumentation/queues-module/#consumer-instrumentation

Suggested Solution

No response

getsantry[bot] commented 2 hours ago

Assigning to @getsentry/support for routing ⏲️