Skip to content

Commit b7c727d

Browse files
committed
fix: complete the expectations
1 parent ec5a288 commit b7c727d

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ public function test_request_response(): void
5757
'http.response.status_code' => 200,
5858
],
5959
'kind' => \OpenTelemetry\API\Trace\SpanKind::KIND_INTERNAL,
60+
'children' => [
61+
[
62+
'name' => 'HTTP GET',
63+
'attributes' => [
64+
'http.request.method' => 'GET',
65+
'url.full' => 'https://opentelemetry.io/',
66+
'url.path' => '/',
67+
'url.scheme' => 'https',
68+
'server.address' => 'opentelemetry.io',
69+
'server.port' => '',
70+
'http.response.status_code' => 200,
71+
'http.response.body.size' => '21765'
72+
],
73+
'kind' => \OpenTelemetry\API\Trace\SpanKind::KIND_CLIENT
74+
]
75+
]
6076
],
6177
],
6278
],

src/Instrumentation/Laravel/tests/Integration/Middleware/MiddlewareTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function test_it_handles_middleware_groups(): void
252252

253253
// Basic response checks
254254
$this->assertEquals(200, $response->status());
255-
255+
256256
$this->assertTraceStructure([
257257
[
258258
'name' => 'GET /middleware-group',
@@ -284,12 +284,32 @@ public function test_it_handles_middleware_groups(): void
284284
[
285285
'name' => 'Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle',
286286
'attributes' => [
287-
'code.function.name' => 'handle',
288-
'code.namespace' => 'Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull',
289287
'laravel.middleware.class' => 'Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull',
290288
'http.response.status_code' => 200,
291289
],
292290
'kind' => \OpenTelemetry\API\Trace\SpanKind::KIND_INTERNAL,
291+
'children' => [
292+
[
293+
'name' => 'Illuminate\Foundation\Http\Middleware\ValidatePostSize::handle',
294+
'attributes' => [
295+
'laravel.middleware.class' => 'Illuminate\Foundation\Http\Middleware\ValidatePostSize',
296+
'http.response.status_code' => 200,
297+
],
298+
'kind' => \OpenTelemetry\API\Trace\SpanKind::KIND_INTERNAL,
299+
'children' => [
300+
[
301+
'name' => 'Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle',
302+
'attributes' => [
303+
'code.function.name' => 'handle',
304+
'code.namespace' => 'Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull',
305+
'laravel.middleware.class' => 'Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull',
306+
'http.response.status_code' => 200,
307+
],
308+
'kind' => \OpenTelemetry\API\Trace\SpanKind::KIND_INTERNAL,
309+
],
310+
],
311+
],
312+
],
293313
],
294314
],
295315
],

src/Instrumentation/Laravel/tests/Integration/TestCase.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,37 @@ protected function assertTraceStructure(array $expectedStructure, string $messag
301301
$actualStructure = $this->getTraceStructure();
302302
$spans = $this->getSpans();
303303

304+
// Helper function to count total spans in expected structure
305+
$countExpectedSpans = function (array $structure) use (&$countExpectedSpans): int {
306+
$count = 1; // Count current span
307+
if (isset($structure['children'])) {
308+
foreach ($structure['children'] as $child) {
309+
$count += $countExpectedSpans($child);
310+
}
311+
}
312+
return $count;
313+
};
314+
315+
// Count total expected spans
316+
$totalExpectedSpans = 0;
317+
foreach ($expectedStructure as $root) {
318+
$totalExpectedSpans += $countExpectedSpans($root);
319+
}
320+
321+
// Count actual spans
322+
$totalActualSpans = count($spans);
323+
324+
// Verify total span count
325+
$this->assertEquals(
326+
$totalExpectedSpans,
327+
$totalActualSpans,
328+
$message ?: sprintf(
329+
'Expected %d total spans, got %d',
330+
$totalExpectedSpans,
331+
$totalActualSpans
332+
)
333+
);
334+
304335
// Helper function to recursively verify span structure
305336
$verifySpan = function (array $expected, ImmutableSpan $actual, array $actualStructure, string $message) use (&$verifySpan): void {
306337
// Verify span properties

0 commit comments

Comments
 (0)