3
3
namespace Sentry \Laravel \Features ;
4
4
5
5
use Closure ;
6
+ use Illuminate \Support \Str ;
6
7
use Illuminate \Contracts \Events \Dispatcher ;
7
8
use Illuminate \Queue \Events \JobExceptionOccurred ;
8
9
use Illuminate \Queue \Events \JobProcessed ;
@@ -68,7 +69,9 @@ public function onBoot(Dispatcher $events): void
68
69
->setOp (self ::QUEUE_SPAN_OP_QUEUE_PUBLISH )
69
70
->setData ([
70
71
'messaging.system ' => 'laravel ' ,
71
- 'messaging.destination.name ' => $ queue ,
72
+ 'messaging.message.id ' => $ payload ['uuid ' ] ?? null ,
73
+ // Jobs pushed onto the Redis driver are formatted as queues:<queue>
74
+ 'messaging.destination.name ' => Str::after ($ queue ?? '' , 'queues: ' ),
72
75
'messaging.destination.connection ' => $ connection ,
73
76
])
74
77
->setDescription ($ queue );
@@ -159,14 +162,16 @@ public function handleJobProcessingQueueEvent(JobProcessing $event): void
159
162
return ;
160
163
}
161
164
162
- // If there is a parent span we can record that job as a child unless configured to not do so
163
- if ($ parentSpan !== null && ! $ this ->isTracingFeatureEnabled ('queue_jobs ' )) {
165
+ // If there is a parent span we can record the job as a child unless the parent is not sample or we are configured to not do so
166
+ if ($ parentSpan !== null && (! $ parentSpan -> getSampled () || ! $ this ->isTracingFeatureEnabled ('queue_jobs ' ) )) {
164
167
return ;
165
168
}
166
169
170
+ $ jobPayload = $ event ->job ->payload ();
171
+
167
172
if ($ parentSpan === null ) {
168
- $ baggage = $ event -> job -> payload () [self ::QUEUE_PAYLOAD_BAGGAGE_DATA ] ?? null ;
169
- $ traceParent = $ event -> job -> payload () [self ::QUEUE_PAYLOAD_TRACE_PARENT_DATA ] ?? null ;
173
+ $ baggage = $ jobPayload [self ::QUEUE_PAYLOAD_BAGGAGE_DATA ] ?? null ;
174
+ $ traceParent = $ jobPayload [self ::QUEUE_PAYLOAD_TRACE_PARENT_DATA ] ?? null ;
170
175
171
176
$ context = continueTrace ($ traceParent ?? '' , $ baggage ?? '' );
172
177
@@ -180,22 +185,19 @@ public function handleJobProcessingQueueEvent(JobProcessing $event): void
180
185
181
186
$ resolvedJobName = $ event ->job ->resolveName ();
182
187
183
- $ receiveLatency = null ;
184
- if ($ event ->job ->payload ()[self ::QUEUE_PAYLOAD_PUBLISH_TIME ] !== null ) {
185
- $ receiveLatency = microtime (true ) - $ event ->job ->payload ()[self ::QUEUE_PAYLOAD_PUBLISH_TIME ];
186
- }
188
+ $ jobPublishedAt = $ jobPayload [self ::QUEUE_PAYLOAD_PUBLISH_TIME ] ?? null ;
187
189
188
190
$ job = [
189
191
'messaging.system ' => 'laravel ' ,
190
-
192
+
191
193
'messaging.destination.name ' => $ event ->job ->getQueue (),
192
194
'messaging.destination.connection ' => $ event ->connectionName ,
193
-
194
- 'messaging.message.id ' => ( string ) $ event -> job -> getJobId () ,
195
+
196
+ 'messaging.message.id ' => $ jobPayload [ ' uuid ' ] ?? null ,
195
197
'messaging.message.envelope.size ' => strlen ($ event ->job ->getRawBody ()),
196
- 'messaging.message.body.size ' => strlen (json_encode ($ event -> job -> payload () ['data ' ])),
198
+ 'messaging.message.body.size ' => strlen (json_encode ($ jobPayload ['data ' ] ?? [ ])),
197
199
'messaging.message.retry.count ' => $ event ->job ->attempts (),
198
- 'messaging.message.receive.latency ' => $ receiveLatency ,
200
+ 'messaging.message.receive.latency ' => $ jobPublishedAt !== null ? microtime ( true ) - $ jobPublishedAt : null ,
199
201
];
200
202
201
203
if ($ context instanceof TransactionContext) {
0 commit comments