@@ -32,6 +32,8 @@ class QueueIntegration extends Feature
32
32
pushScope as private pushScopeTrait;
33
33
}
34
34
35
+ private const QUEUE_SPAN_OP_QUEUE_PUBLISH = 'queue.publish ' ;
36
+
35
37
private const QUEUE_PAYLOAD_BAGGAGE_DATA = 'sentry_baggage_data ' ;
36
38
private const QUEUE_PAYLOAD_TRACE_PARENT_DATA = 'sentry_trace_parent_data ' ;
37
39
@@ -57,7 +59,22 @@ public function onBoot(Dispatcher $events): void
57
59
$ events ->listen (JobExceptionOccurred::class, [$ this , 'handleJobExceptionOccurredQueueEvent ' ]);
58
60
59
61
if ($ this ->isTracingFeatureEnabled ('queue_jobs ' ) || $ this ->isTracingFeatureEnabled ('queue_job_transactions ' )) {
60
- Queue::createPayloadUsing (static function (?string $ connection , ?string $ queue , ?array $ payload ): ?array {
62
+ Queue::createPayloadUsing (function (?string $ connection , ?string $ queue , ?array $ payload ): ?array {
63
+ $ parentSpan = SentrySdk::getCurrentHub ()->getSpan ();
64
+
65
+ if ($ parentSpan !== null ) {
66
+ $ context = (new SpanContext )
67
+ ->setOp (self ::QUEUE_SPAN_OP_QUEUE_PUBLISH )
68
+ ->setData ([
69
+ 'messaging.system ' => 'laravel ' ,
70
+ 'messaging.destination.name ' => $ queue ,
71
+ 'messaging.destination.connection ' => $ connection ,
72
+ ])
73
+ ->setDescription ($ queue );
74
+
75
+ $ this ->pushSpan ($ parentSpan ->startChild ($ context ));
76
+ }
77
+
61
78
if ($ payload !== null ) {
62
79
$ payload [self ::QUEUE_PAYLOAD_BAGGAGE_DATA ] = getBaggage ();
63
80
$ payload [self ::QUEUE_PAYLOAD_TRACE_PARENT_DATA ] = getTraceparent ();
@@ -70,10 +87,10 @@ public function onBoot(Dispatcher $events): void
70
87
71
88
public function handleJobQueueingEvent (JobQueueing $ event ): void
72
89
{
73
- $ parentSpan = SentrySdk::getCurrentHub ()->getSpan ();
90
+ $ currentSpan = SentrySdk::getCurrentHub ()->getSpan ();
74
91
75
92
// If there is no tracing span active there is no need to handle the event
76
- if ($ parentSpan === null ) {
93
+ if ($ currentSpan === null || $ currentSpan -> getOp () !== self :: QUEUE_SPAN_OP_QUEUE_PUBLISH ) {
77
94
return ;
78
95
}
79
96
@@ -85,16 +102,11 @@ public function handleJobQueueingEvent(JobQueueing $event): void
85
102
$ jobName = get_class ($ jobName );
86
103
}
87
104
88
- $ context = (new SpanContext )
89
- ->setOp ('queue.publish ' )
105
+ $ currentSpan
90
106
->setData ([
91
- 'messaging.system ' => 'laravel ' ,
92
107
'messaging.laravel.job ' => $ jobName ,
93
- 'messaging.destination.connection ' => $ event ->connectionName ,
94
108
])
95
109
->setDescription ($ jobName );
96
-
97
- $ this ->pushSpan ($ parentSpan ->startChild ($ context ));
98
110
}
99
111
100
112
public function handleJobQueuedEvent (JobQueued $ event ): void
0 commit comments