Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Feb 28, 2024
1 parent 0c4d451 commit 045bd25
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/Application/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
framework:
secret: ThisIsSecret
test: true
fragments: { path: /_fragment }
6 changes: 6 additions & 0 deletions tests/Application/src/Controller/DummyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public function view(): Response
{
return $this->render('dummy.html.twig');
}

#[Route('/fragment', methods: ['GET'])]
public function segment(): Response
{
return $this->render('fragment.html.twig');
}
}
4 changes: 4 additions & 0 deletions tests/Application/templates/fragment.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>fragment</h1>
<p>
{{ render(controller('FriendsOfOpenTelemetry\\OpenTelemetryBundle\\Tests\\Application\\Controller\\DummyController::view')) }}
</p>
80 changes: 80 additions & 0 deletions tests/Functional/Instrumentation/ControllerTracingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,86 @@ public function testView(): void
self::assertSpanEventsCount($mainSpan, 0);
}

public function testFragment(): void
{
$client = static::createClient();
$client->request('GET', '/fragment');

static::assertResponseIsSuccessful();
static::assertSame(<<<'HTML'
<h1>fragment</h1>
<p>
<h1>Hello World</h1>
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</p>
HTML, trim($client->getResponse()->getContent()));

self::assertSpansCount(5);

$partialViewSpan = self::getSpans()[0];
self::assertSpanName($partialViewSpan, 'partial/test.html.twig');
self::assertSpanStatus($partialViewSpan, StatusData::unset());
self::assertSpanAttributes($partialViewSpan, []);
self::assertSpanEventsCount($partialViewSpan, 0);

$viewSpan = self::getSpans()[1];
self::assertSpanName($viewSpan, 'dummy.html.twig');
self::assertSpanStatus($viewSpan, StatusData::unset());
self::assertSpanAttributes($viewSpan, []);
self::assertSpanEventsCount($viewSpan, 0);

$nativeFragmentSpan = self::getSpans()[2];
self::assertSpanName($nativeFragmentSpan, 'HTTP GET');
self::assertSpanStatus($nativeFragmentSpan, StatusData::ok());
self::assertSpanAttributes($nativeFragmentSpan, [
'url.full' => 'http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3DFriendsOfOpenTelemetry%255COpenTelemetryBundle%255CTests%255CApplication%255CController%255CDummyController%253A%253Aview',
'http.request.method' => 'GET',
'url.path' => '/_fragment',
'symfony.kernel.http.host' => 'localhost',
'url.scheme' => 'http',
'network.protocol.version' => '1.0',
'user_agent.original' => 'Symfony BrowserKit',
'network.peer.address' => '127.0.0.1',
'symfony.kernel.net.peer_ip' => '127.0.0.1',
'server.address' => 'localhost',
'server.port' => 80,
'http.response.status_code' => Response::HTTP_OK,
]);
self::assertSpanEventsCount($nativeFragmentSpan, 0);

$fragmentSpan = self::getSpans()[3];
self::assertSpanName($fragmentSpan, 'fragment.html.twig');
self::assertSpanStatus($fragmentSpan, StatusData::unset());
self::assertSpanAttributes($fragmentSpan, []);
self::assertSpanEventsCount($fragmentSpan, 0);

$mainSpan = self::getSpans()[4];
self::assertSpanName($mainSpan, 'friendsofopentelemetry_opentelemetry_tests_application_dummy_segment');
self::assertSpanStatus($mainSpan, StatusData::ok());
self::assertSpanAttributes($mainSpan, [
'url.full' => 'http://localhost/fragment',
'http.request.method' => 'GET',
'url.path' => '/fragment',
'symfony.kernel.http.host' => 'localhost',
'url.scheme' => 'http',
'network.protocol.version' => '1.1',
'user_agent.original' => 'Symfony BrowserKit',
'network.peer.address' => '127.0.0.1',
'symfony.kernel.net.peer_ip' => '127.0.0.1',
'server.address' => 'localhost',
'server.port' => 80,
'http.route' => 'friendsofopentelemetry_opentelemetry_tests_application_dummy_segment',
'http.response.status_code' => 200,
]);
self::assertSpanEventsCount($mainSpan, 0);
}

public function testFailure(): void
{
$client = static::createClient();
Expand Down

0 comments on commit 045bd25

Please sign in to comment.