Skip to content

Commit 5093704

Browse files
committed
chore: migrate to trace structure
1 parent e09ab98 commit 5093704

File tree

1 file changed

+44
-53
lines changed

1 file changed

+44
-53
lines changed

src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php

+44-53
Original file line numberDiff line numberDiff line change
@@ -224,32 +224,20 @@ public function test_handle_message()
224224
$handleMessageMethod->setAccessible(true);
225225
$handleMessageMethod->invoke($worker, $message, 'transport');
226226

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+
]
251240
);
252-
$this->assertEquals(SpanKind::KIND_CONSUMER, $consumeSpan->getKind());
253241
}
254242

255243
public function test_middleware_instrumentation()
@@ -282,22 +270,22 @@ public function handle(Envelope $envelope, \Symfony\Component\Messenger\Middlewa
282270
}
283271
});
284272

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+
);
301289
}
302290

303291
public function test_stamp_information()
@@ -315,20 +303,23 @@ public function test_stamp_information()
315303
$transport->send($envelope);
316304

317305
// 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+
);
330320

331321
// Check stamps count
322+
$sendSpan = $this->storage[0];
332323
$this->assertTrue($sendSpan->getAttributes()->has('messaging.symfony.stamps'));
333324
$stamps = json_decode($sendSpan->getAttributes()->get('messaging.symfony.stamps'), true);
334325
$this->assertIsArray($stamps);

0 commit comments

Comments
 (0)