Skip to content

Commit

Permalink
Cache routes
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Dec 17, 2024
1 parent 2970e08 commit 7233cec
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 41 deletions.
22 changes: 13 additions & 9 deletions appsec/tests/integration/src/docker/php/build_dev_php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ function run_dsymutil {
fi
local readonly dir=$1 exe=
find "$dir" -type f -exec test -x '{}' \; -print | while read -r exe; do
if ! grep -q '^#!' "$exe"; then
local readonly dSYM_DIR="${exe}.dSYM"
if [[ ! -d $dSYM_DIR ]]; then
dsymutil "$exe"
if [[ $exe != *.a ]]; then
if ! grep -q '^#!' "$exe"; then
local readonly dSYM_DIR="${exe}.dSYM"
if [[ ! -d $dSYM_DIR ]]; then
dsymutil "$exe"
fi
fi
fi
done
Expand All @@ -98,14 +100,16 @@ function run_dsymutil {
function get_xdebug_version {
local -r version=$1
local readonly version_id=$(php_version_id $version)
if [[ $version_id -lt 70300 ]]; then
echo '2.8.1'
elif [[ $version_id -lt 80000 ]]; then
if [[ $version_id -lt 70100 ]]; then
echo '2.6.1'
elif [[ $version_id -lt 70200 ]]; then
echo '2.9.8'
elif [[ $version_id -lt 80000 ]]; then
echo '3.1.6'
elif [[ $version_id -lt 80400 ]]; then
echo '3.3.1'
echo '3.3.2'
elif [[ $version_id -ge 80400 ]]; then
echo '3.4.0beta1'
echo '3.4.0'
fi
}

Expand Down
55 changes: 40 additions & 15 deletions src/DDTrace/Integrations/Symfony/SymfonyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use DDTrace\Tag;
use DDTrace\Type;
use DDTrace\Util\Normalizer;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Contracts\Cache\ItemInterface;

class SymfonyIntegration extends Integration
{
Expand Down Expand Up @@ -419,21 +421,44 @@ function_exists('datadog\appsec\push_address')) {
}

$route_name = $request->get('_route');
if (null !== $route_name && null !== $request) {
if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) {
$rootSpan->resource = $route_name;
}
$rootSpan->meta['symfony.route.name'] = $route_name;

if ($integration->kernel !== null) {
$container = $integration->kernel->getContainer();
$router = $container->get('router');
$routeCollection = $router->getRouteCollection();
$route = $routeCollection->get($route_name);
if (isset($route)) {
$rootSpan->meta[Tag::HTTP_ROUTE] = $route->getPath();
}
}
if ($route_name === null) {
return;
}
if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) {
$rootSpan->resource = $route_name;
}
$rootSpan->meta['symfony.route.name'] = $route_name;

// the rest is for determining http.route
if ($integration->kernel === null) {
return;
}
/** @var ContainerInterface $container */
$container = $integration->kernel->getContainer();
$cache = null;
try {
$cache = $container->get('cache.app');
} catch (\Exception $e) {
return;
}

/** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
$router = $container->get('router');
if (!\method_exists($cache, 'getItem')) {
return;
}
$item = $cache->getItem("_datadog.route.path.$route_name");
if ($item->isHit()) {
$route = $item->get();
} else {
$routeCollection = $router->getRouteCollection();
$route = $routeCollection->get($route_name);
$item->set($route);
$item->expiresAfter(3600);
$cache->save($item);
}
if (isset($route)) {
$rootSpan->meta[Tag::HTTP_ROUTE] = $route->getPath();
}
}
);
Expand Down
3 changes: 0 additions & 3 deletions tests/Integrations/Symfony/V3_0/CommonScenariosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function provideSpecs()
)->withExactTags([
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
'symfony.route.name' => 'simple',
'http.route' => '/simple',
'http.method' => 'GET',
'http.url' => 'http://localhost/simple?key=value&<redacted>',
'http.status_code' => '200',
Expand Down Expand Up @@ -80,7 +79,6 @@ public function provideSpecs()
)->withExactTags([
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleViewAction',
'symfony.route.name' => 'simple_view',
'http.route' => '/simple_view',
'http.method' => 'GET',
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
'http.status_code' => '200',
Expand Down Expand Up @@ -127,7 +125,6 @@ public function provideSpecs()
)->withExactTags([
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@errorAction',
'symfony.route.name' => 'error',
'http.route' => '/error',
'http.method' => 'GET',
'http.url' => 'http://localhost/error?key=value&<redacted>',
'http.status_code' => '500',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"error.stack": "#0 [internal function]: Drupal\\datadog\\Controller\\DatadogController->error()\n#1 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()\n#2 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/Render/Renderer.php(592): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#3 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\\Core\\Render\\Renderer->executeInRenderContext()\n#4 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()\n#5 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#6 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#7 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#8 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\\Core\\StackMiddleware\\Session->handle()\n#9 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle()\n#10 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle()\n#11 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle()\n#12 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\\Core\\StackMiddleware\\StackedHttpKernel->handle()\n#13 /home/circleci/app/tests/Frameworks/Drupal/Version_10_1/index.php(19): Drupal\\Core\\DrupalKernel->handle()\n#14 {main}",
"error.type": "Exception",
"http.method": "GET",
"http.route": "/error",
"http.status_code": "500",
"http.url": "http://localhost/error?key=value&<redacted>",
"runtime-id": "9909a648-1886-44d2-b341-b1ddc0f62f34",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"_dd.p.dm": "-0",
"component": "drupal",
"http.method": "GET",
"http.route": "/simple_view",
"http.status_code": "200",
"http.url": "http://localhost/simple_view",
"runtime-id": "cecb7d5b-eb5a-49f8-8374-29dce2d6fce6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"error.stack": "#0 [internal function]: Drupal\\datadog\\Controller\\DatadogController->error()\n#1 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()\n#2 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#3 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\\Core\\Render\\Renderer->executeInRenderContext()\n#4 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()\n#5 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#6 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#7 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#8 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\\Core\\StackMiddleware\\Session->handle()\n#9 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle()\n#10 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle()\n#11 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle()\n#12 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\\StackedHttpKernel->handle()\n#13 /home/circleci/app/tests/Frameworks/Drupal/Version_8_9/index.php(19): Drupal\\Core\\DrupalKernel->handle()\n#14 {main}",
"error.type": "Exception",
"http.method": "GET",
"http.route": "/error",
"http.status_code": "500",
"http.url": "http://localhost/error?key=value&<redacted>",
"runtime-id": "692423cd-81b3-449e-a67e-43150df99f74",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"_dd.p.dm": "-0",
"component": "drupal",
"http.method": "GET",
"http.route": "/simple_view",
"http.status_code": "200",
"http.url": "http://localhost/simple_view",
"runtime-id": "692423cd-81b3-449e-a67e-43150df99f74",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"error.stack": "#0 [internal function]: Drupal\\datadog\\Controller\\DatadogController->error()\n#1 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()\n#2 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#3 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\\Core\\Render\\Renderer->executeInRenderContext()\n#4 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()\n#5 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#6 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#7 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#8 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\\Core\\StackMiddleware\\Session->handle()\n#9 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle()\n#10 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle()\n#11 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle()\n#12 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\\StackedHttpKernel->handle()\n#13 /home/circleci/app/tests/Frameworks/Drupal/Version_9_5/index.php(19): Drupal\\Core\\DrupalKernel->handle()\n#14 {main}",
"error.type": "Exception",
"http.method": "GET",
"http.route": "/error",
"http.status_code": "500",
"http.url": "http://localhost/error?key=value&<redacted>",
"runtime-id": "3afe4427-fcda-4ade-bdc5-572a8c5f8b12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"_dd.p.dm": "-0",
"component": "drupal",
"http.method": "GET",
"http.route": "/simple_view",
"http.status_code": "200",
"http.url": "http://localhost/simple_view",
"runtime-id": "7a7b1e1f-04e8-41dc-82bd-81f24ef6e0a4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"_dd.p.tid": "6661b34000000000",
"component": "symfony",
"http.method": "GET",
"http.route": "/simple",
"http.status_code": "200",
"http.url": "http://localhost/app.php/simple?key=value&<redacted>",
"runtime-id": "93535b2f-0ff1-4add-8907-53304703f545",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"error.type": "Exception",
"http.method": "GET",
"http.status_code": "500",
"http.route": "/error",
"http.url": "http://localhost/app.php/error?key=value&<redacted>",
"runtime-id": "93535b2f-0ff1-4add-8907-53304703f545",
"span.kind": "server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"_dd.p.tid": "6661bc6500000000",
"component": "symfony",
"http.method": "GET",
"http.route": "/simple_view",
"http.status_code": "200",
"http.url": "http://localhost/app.php/simple_view?key=value&<redacted>",
"runtime-id": "05d2d546-7cb6-4e46-bc10-0ff5602cdf9d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"_dd.p.tid": "6661b35800000000",
"component": "symfony",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"http.url": "http://localhost/app.php?key=value&<redacted>",
"runtime-id": "7ddbbd63-c083-4257-a7f5-44101e551ef1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"_dd.p.tid": "6660700300000000",
"component": "symfony",
"http.method": "GET",
"http.route": "/simple",
"http.status_code": "200",
"http.url": "http://localhost/app.php/simple?key=value&<redacted>",
"runtime-id": "4374c14f-def1-4b62-97c0-598f46322850",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"error.stack": "#0 /home/circleci/app/tests/Frameworks/Symfony/Version_2_8/app/bootstrap.php.cache(3275): AppBundle\\Controller\\CommonScenariosController->errorAction()\n#1 /home/circleci/app/tests/Frameworks/Symfony/Version_2_8/app/bootstrap.php.cache(3234): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#2 /home/circleci/app/tests/Frameworks/Symfony/Version_2_8/app/bootstrap.php.cache(3388): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#3 /home/circleci/app/tests/Frameworks/Symfony/Version_2_8/app/bootstrap.php.cache(2594): Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel->handle()\n#4 /home/circleci/app/tests/Frameworks/Symfony/Version_2_8/web/app.php(15): Symfony\\Component\\HttpKernel\\Kernel->handle()\n#5 {main}",
"error.type": "Exception",
"http.method": "GET",
"http.route": "/error",
"http.status_code": "500",
"http.url": "http://localhost/app.php/error?key=value&<redacted>",
"runtime-id": "4374c14f-def1-4b62-97c0-598f46322850",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"_dd.p.tid": "6660709f00000000",
"component": "symfony",
"http.method": "GET",
"http.route": "/simple_view",
"http.status_code": "200",
"http.url": "http://localhost/app.php/simple_view?key=value&<redacted>",
"runtime-id": "a908b910-f481-44e7-bf7b-8d48954a4639",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"_dd.p.tid": "6660aaff00000000",
"component": "symfony",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"http.url": "http://localhost/app.php?key=value&<redacted>",
"runtime-id": "4b578cb2-1f1d-441e-aacb-a4aaff240713",
Expand Down

0 comments on commit 7233cec

Please sign in to comment.