@@ -224,32 +224,20 @@ public function test_handle_message()
224
224
$ handleMessageMethod ->setAccessible (true );
225
225
$ handleMessageMethod ->invoke ($ worker , $ message , 'transport ' );
226
226
227
- // We should have 3 spans: send, dispatch, and consume
228
- $ this ->assertCount (3 , $ this ->storage );
229
-
230
- // Check the send span
231
- $ sendSpan = $ this ->storage [0 ];
232
- $ this ->assertEquals (
233
- 'SEND OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage ' ,
234
- $ sendSpan ->getName ()
235
- );
236
- $ this ->assertEquals (SpanKind::KIND_PRODUCER , $ sendSpan ->getKind ());
237
-
238
- // Check the dispatch span
239
- $ dispatchSpan = $ this ->storage [1 ];
240
- $ this ->assertEquals (
241
- 'DISPATCH Symfony\Component\Messenger\Envelope ' ,
242
- $ dispatchSpan ->getName ()
243
- );
244
- $ this ->assertEquals (SpanKind::KIND_PRODUCER , $ dispatchSpan ->getKind ());
245
-
246
- // Check the consume span
247
- $ consumeSpan = $ this ->storage [2 ];
248
- $ this ->assertEquals (
249
- 'CONSUME OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage ' ,
250
- $ consumeSpan ->getName ()
227
+ // We should have 2 spans: send and consume
228
+ $ this ->assertTraceStructure (
229
+ $ this ->storage ,
230
+ [
231
+ [
232
+ 'name ' => 'SEND OpenTelemetry \\Tests \\Instrumentation \\Symfony \\tests \\Integration \\SendEmailMessage ' ,
233
+ 'kind ' => SpanKind::KIND_PRODUCER ,
234
+ ],
235
+ [
236
+ 'name ' => 'CONSUME OpenTelemetry \\Tests \\Instrumentation \\Symfony \\tests \\Integration \\SendEmailMessage ' ,
237
+ 'kind ' => SpanKind::KIND_CONSUMER ,
238
+ ],
239
+ ]
251
240
);
252
- $ this ->assertEquals (SpanKind::KIND_CONSUMER , $ consumeSpan ->getKind ());
253
241
}
254
242
255
243
public function test_middleware_instrumentation ()
@@ -282,22 +270,22 @@ public function handle(Envelope $envelope, \Symfony\Component\Messenger\Middlewa
282
270
}
283
271
});
284
272
285
- // Find the middleware span
286
- $ middlewareSpan = null ;
287
- foreach ( $ this ->storage as $ span ) {
288
- if ( strpos ( $ span -> getName (), ' MIDDLEWARE ' ) === 0 ) {
289
- $ middlewareSpan = $ span ;
290
-
291
- break ;
292
- }
293
- }
294
-
295
- // Assert we found the middleware span
296
- $ this ->assertNotNull ( $ middlewareSpan , ' Middleware span not found ' );
297
- $ this -> assertStringStartsWith ( ' MIDDLEWARE ' , $ middlewareSpan -> getName ());
298
- $ this -> assertStringEndsWith ( ' SendEmailMessage ' , $ middlewareSpan -> getName ());
299
- $ this -> assertEquals (SpanKind:: KIND_INTERNAL , $ middlewareSpan -> getKind ());
300
- $ this -> assertTrue ( $ middlewareSpan -> getAttributes ()-> has (MessengerInstrumentation:: ATTRIBUTE_MESSAGING_MIDDLEWARE ) );
273
+ // Use assertTraceStructure with PHPUnit constraints
274
+ $ this -> assertTraceStructure (
275
+ $ this ->storage ,
276
+ [
277
+ [
278
+ ' name ' => $ this -> logicalAnd (
279
+ $ this -> stringStartsWith ( ' MIDDLEWARE ' ),
280
+ $ this -> stringContains ( ' SendEmailMessage ' )
281
+ ),
282
+ ' kind ' => SpanKind:: KIND_INTERNAL ,
283
+ ' attributes ' => [
284
+ MessengerInstrumentation:: ATTRIBUTE_MESSAGING_MIDDLEWARE => $ this ->logicalNot ( $ this -> isEmpty ()),
285
+ ],
286
+ ],
287
+ ]
288
+ );
301
289
}
302
290
303
291
public function test_stamp_information ()
@@ -315,20 +303,23 @@ public function test_stamp_information()
315
303
$ transport ->send ($ envelope );
316
304
317
305
// We should have a send span with all stamp information
318
- $ this ->assertCount (1 , $ this ->storage );
319
- $ sendSpan = $ this ->storage [0 ];
320
-
321
- // Check stamp attributes
322
- $ this ->assertTrue ($ sendSpan ->getAttributes ()->has ('messaging.symfony.bus ' ));
323
- $ this ->assertEquals ('test_bus ' , $ sendSpan ->getAttributes ()->get ('messaging.symfony.bus ' ));
324
-
325
- $ this ->assertTrue ($ sendSpan ->getAttributes ()->has ('messaging.symfony.delay ' ));
326
- $ this ->assertEquals (1000 , $ sendSpan ->getAttributes ()->get ('messaging.symfony.delay ' ));
327
-
328
- $ this ->assertTrue ($ sendSpan ->getAttributes ()->has (TraceAttributes::MESSAGING_MESSAGE_ID ));
329
- $ this ->assertEquals ('test-id ' , $ sendSpan ->getAttributes ()->get (TraceAttributes::MESSAGING_MESSAGE_ID ));
306
+ $ this ->assertTraceStructure (
307
+ $ this ->storage ,
308
+ [
309
+ [
310
+ 'name ' => 'SEND OpenTelemetry \\Tests \\Instrumentation \\Symfony \\tests \\Integration \\SendEmailMessage ' ,
311
+ 'kind ' => SpanKind::KIND_PRODUCER ,
312
+ 'attributes ' => [
313
+ 'messaging.symfony.bus ' => 'test_bus ' ,
314
+ 'messaging.symfony.delay ' => 1000 ,
315
+ TraceAttributes::MESSAGING_MESSAGE_ID => 'test-id ' ,
316
+ ],
317
+ ],
318
+ ]
319
+ );
330
320
331
321
// Check stamps count
322
+ $ sendSpan = $ this ->storage [0 ];
332
323
$ this ->assertTrue ($ sendSpan ->getAttributes ()->has ('messaging.symfony.stamps ' ));
333
324
$ stamps = json_decode ($ sendSpan ->getAttributes ()->get ('messaging.symfony.stamps ' ), true );
334
325
$ this ->assertIsArray ($ stamps );
0 commit comments