Skip to content

Commit a1694e1

Browse files
committed
fix(Instrumentation/HttpKernel): empty exclude config should not exclude all routes
1 parent 76e89fe commit a1694e1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/Instrumentation/Symfony/HttpKernel/TraceableHttpKernelEventSubscriber.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ private function isAutoTraceable(Request $request): bool
290290
return false;
291291
}
292292

293+
if (0 === count($this->excludePaths)) {
294+
return true;
295+
}
296+
293297
$combinedExcludePaths = implode('|', $this->excludePaths);
294298
if (preg_match("#{$combinedExcludePaths}#", $request->getPathInfo())) {
295299
return false;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\Tests\Functional\Instrumentation\HttpKernel;
4+
5+
use App\Kernel;
6+
use FriendsOfOpenTelemetry\OpenTelemetryBundle\Tests\Functional\TracingTestCaseTrait;
7+
use OpenTelemetry\SDK\Trace\StatusData;
8+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9+
use Symfony\Component\HttpFoundation\Response;
10+
use Zalas\PHPUnit\Globals\Attribute\Env;
11+
12+
#[Env('KERNEL_CLASS', Kernel::class)]
13+
#[Env('APP_ENV', 'empty_excludes')]
14+
class HttpKernelEmptyExcludesTracingTest extends WebTestCase
15+
{
16+
use TracingTestCaseTrait;
17+
18+
public function testSuccess(): void
19+
{
20+
$client = static::createClient();
21+
$client->request('GET', '/auto-traceable');
22+
23+
static::assertResponseIsSuccessful();
24+
static::assertSame('{"status":"ok"}', $client->getResponse()->getContent());
25+
26+
self::assertSpansCount(1);
27+
28+
$mainSpan = self::getSpans()[0];
29+
self::assertSpanName($mainSpan, 'app_traceable_autotraceable_index');
30+
self::assertSpanStatus($mainSpan, StatusData::ok());
31+
self::assertSpanAttributes($mainSpan, [
32+
'url.full' => 'http://localhost/auto-traceable',
33+
'http.request.method' => 'GET',
34+
'url.path' => '/auto-traceable',
35+
'symfony.kernel.http.host' => 'localhost',
36+
'url.scheme' => 'http',
37+
'network.protocol.version' => '1.1',
38+
'user_agent.original' => 'Symfony BrowserKit',
39+
'network.peer.address' => '127.0.0.1',
40+
'symfony.kernel.net.peer_ip' => '127.0.0.1',
41+
'server.address' => 'localhost',
42+
'server.port' => 80,
43+
'http.route' => 'app_traceable_autotraceable_index',
44+
'http.response.status_code' => Response::HTTP_OK,
45+
]);
46+
self::assertSpanEventsCount($mainSpan, 0);
47+
}
48+
}

0 commit comments

Comments
 (0)