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 d207d8d commit 0c4d451
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetryBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
Expand All @@ -15,6 +16,7 @@ public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
new TwigBundle(),
new OpenTelemetryBundle(),
];
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Application/config/packages/open_telemetry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ open_telemetry:
http_kernel:
tracing:
enabled: true
twig:
tracing:
enabled: true
traces:
tracers:
main:
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
twig:
default_path: '%kernel.project_dir%/templates'
6 changes: 6 additions & 0 deletions tests/Application/src/Controller/DummyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public function index(Request $request): Response
'status' => 'ok',
]);
}

#[Route('/view', methods: ['GET'])]
public function view(): Response
{
return $this->render('dummy.html.twig');
}
}
2 changes: 2 additions & 0 deletions tests/Application/templates/dummy.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello World</h1>
{{ include('partial/test.html.twig') }}
5 changes: 5 additions & 0 deletions tests/Application/templates/partial/test.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
50 changes: 50 additions & 0 deletions tests/Functional/Instrumentation/ControllerTracingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,56 @@ public function testSuccess(): void
self::assertSpanEventsCount($mainSpan, 0);
}

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

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

self::assertSpansCount(3);

$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);

$mainSpan = self::getSpans()[2];
self::assertSpanName($mainSpan, 'friendsofopentelemetry_opentelemetry_tests_application_dummy_view');
self::assertSpanStatus($mainSpan, StatusData::ok());
self::assertSpanAttributes($mainSpan, [
'url.full' => 'http://localhost/view',
'http.request.method' => 'GET',
'url.path' => '/view',
'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_view',
'http.response.status_code' => Response::HTTP_OK,
]);
self::assertSpanEventsCount($mainSpan, 0);
}

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

0 comments on commit 0c4d451

Please sign in to comment.