diff --git a/Makefile b/Makefile index 1037ea3bf2..665e450dff 100644 --- a/Makefile +++ b/Makefile @@ -1031,7 +1031,6 @@ TEST_WEB_83 := \ test_web_nette_30 \ test_web_slim_312 \ test_web_slim_4 \ - test_web_symfony_52 \ test_web_symfony_62 \ test_web_symfony_70 \ test_web_wordpress_59 \ diff --git a/src/DDTrace/Integrations/Symfony/SymfonyIntegration.php b/src/DDTrace/Integrations/Symfony/SymfonyIntegration.php index 80668f9d9c..c28219d83e 100644 --- a/src/DDTrace/Integrations/Symfony/SymfonyIntegration.php +++ b/src/DDTrace/Integrations/Symfony/SymfonyIntegration.php @@ -10,9 +10,7 @@ use DDTrace\Type; use DDTrace\Util\Normalizer; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Routing\Route; class SymfonyIntegration extends Integration { @@ -24,6 +22,8 @@ class SymfonyIntegration extends Integration /** @var string */ public $frameworkPrefix = SymfonyIntegration::NAME; + public $kernel; + /** * {@inheritdoc} */ @@ -309,42 +309,6 @@ function ($This, $scope, $args) use ($integration) { } ); - \DDTrace\trace_method( - 'Symfony\Component\EventDispatcher\EventDispatcher', - 'dispatch', - function (SpanData $span, $args) { - $event = $args[0]; - - if (!($event instanceof ControllerEvent)) { - return; - } - - $request = $event->getRequest(); - $controller = $event->getController()[0]; - - if (!property_exists($controller, 'container')) { - return; - } - - $rc = new \ReflectionClass(get_class($controller)); - $container = $rc->getProperty('container'); - $container->setAccessible(true); - $container = $container->getValue($controller); - - $router = $container->get('router'); - $routeName = $request->attributes->get('_route'); - - $routeCollection = $router->getRouteCollection(); - /** @var Route $route */ - $route = $routeCollection->get($routeName); - if (!isset($route)) { - return; - } - $root_span = \DDTrace\root_span(); - $root_span->meta[Tag::HTTP_ROUTE] = $route->getPath(); - } - ); - $this->loadSymfony($this); return Integration::LOADED; @@ -393,6 +357,24 @@ function (SpanData $span) use ($class, $methodname) { ); */ + \DDTrace\hook_method( + 'Symfony\Component\HttpKernel\Kernel', + 'getHttpKernel', + null, + function ($object) use ($integration) { + $integration->kernel = $object; + } + ); + + \DDTrace\hook_method( + 'Drupal\Core\DrupalKernel', + 'getHttpKernel', + null, + function ($object) use ($integration) { + $integration->kernel = $object; + } + ); + \DDTrace\hook_method( 'Symfony\Component\HttpKernel\HttpKernel', '__construct', @@ -436,12 +418,22 @@ function_exists('datadog\appsec\push_address')) { \datadog\appsec\push_address("server.request.path_params", $parameters); } - $route = $request->get('_route'); - if (null !== $route && null !== $request) { + $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; + $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(); + } } - $rootSpan->meta['symfony.route.name'] = $route; } } ); diff --git a/tests/snapshots/tests.integrations.drupal.v10_1.common_scenarios_test.test_scenario_get_with_view.json b/tests/snapshots/tests.integrations.drupal.v10_1.common_scenarios_test.test_scenario_get_with_view.json index 16afc5508e..53ccf7e10f 100644 --- a/tests/snapshots/tests.integrations.drupal.v10_1.common_scenarios_test.test_scenario_get_with_view.json +++ b/tests/snapshots/tests.integrations.drupal.v10_1.common_scenarios_test.test_scenario_get_with_view.json @@ -11,6 +11,7 @@ "_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", diff --git a/tests/snapshots/tests.integrations.drupal.v8_9.common_scenarios_test.test_scenario_get_with_view.json b/tests/snapshots/tests.integrations.drupal.v8_9.common_scenarios_test.test_scenario_get_with_view.json index 42eaba32f3..50d551be74 100644 --- a/tests/snapshots/tests.integrations.drupal.v8_9.common_scenarios_test.test_scenario_get_with_view.json +++ b/tests/snapshots/tests.integrations.drupal.v8_9.common_scenarios_test.test_scenario_get_with_view.json @@ -11,6 +11,7 @@ "_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", diff --git a/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_exception.json b/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_exception.json index d6a0f8f00d..15760a4b54 100644 --- a/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_exception.json +++ b/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_exception.json @@ -15,6 +15,7 @@ "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&", "runtime-id": "3afe4427-fcda-4ade-bdc5-572a8c5f8b12", diff --git a/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_view.json b/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_view.json index fbcc57a8a7..870ca01550 100644 --- a/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_view.json +++ b/tests/snapshots/tests.integrations.drupal.v9_5.common_scenarios_test.test_scenario_get_with_view.json @@ -11,6 +11,7 @@ "_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", diff --git a/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_return_string.json b/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_return_string.json index 82348173bb..47f6496617 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_return_string.json +++ b/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_return_string.json @@ -12,6 +12,7 @@ "_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&", "runtime-id": "93535b2f-0ff1-4add-8907-53304703f545", diff --git a/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_exception.json b/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_exception.json index e76f67bda8..aa81c0b610 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_exception.json +++ b/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_exception.json @@ -17,6 +17,7 @@ "error.type": "Exception", "http.method": "GET", "http.status_code": "500", + "http.route": "/error", "http.url": "http://localhost/app.php/error?key=value&", "runtime-id": "93535b2f-0ff1-4add-8907-53304703f545", "span.kind": "server", diff --git a/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_view.json b/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_view.json index 02531a7ac6..3ac43968e0 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_view.json +++ b/tests/snapshots/tests.integrations.symfony.v2_3.common_scenarios_test.test_scenario_get_with_view.json @@ -12,6 +12,7 @@ "_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&", "runtime-id": "05d2d546-7cb6-4e46-bc10-0ff5602cdf9d", diff --git a/tests/snapshots/tests.integrations.symfony.v2_3.route_name_test.test_resource_to_uri_mapping.json b/tests/snapshots/tests.integrations.symfony.v2_3.route_name_test.test_resource_to_uri_mapping.json index 420610342c..f737bfa91e 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_3.route_name_test.test_resource_to_uri_mapping.json +++ b/tests/snapshots/tests.integrations.symfony.v2_3.route_name_test.test_resource_to_uri_mapping.json @@ -12,6 +12,7 @@ "_dd.p.tid": "6661b35800000000", "component": "symfony", "http.method": "GET", + "http.route": "/", "http.status_code": "200", "http.url": "http://localhost/app.php?key=value&", "runtime-id": "7ddbbd63-c083-4257-a7f5-44101e551ef1", diff --git a/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_return_string.json b/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_return_string.json index a0a9c47464..706a7dcb5c 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_return_string.json +++ b/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_return_string.json @@ -12,6 +12,7 @@ "_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&", "runtime-id": "4374c14f-def1-4b62-97c0-598f46322850", diff --git a/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_exception.json b/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_exception.json index d5292f1bbf..c1798e3aba 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_exception.json +++ b/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_exception.json @@ -16,6 +16,7 @@ "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&", "runtime-id": "4374c14f-def1-4b62-97c0-598f46322850", diff --git a/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_view.json b/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_view.json index 37bea1d81a..89d499bfa9 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_view.json +++ b/tests/snapshots/tests.integrations.symfony.v2_8.common_scenarios_test.test_scenario_get_with_view.json @@ -12,6 +12,7 @@ "_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&", "runtime-id": "a908b910-f481-44e7-bf7b-8d48954a4639", diff --git a/tests/snapshots/tests.integrations.symfony.v2_8.route_name_test.test_resource_to_uri_mapping.json b/tests/snapshots/tests.integrations.symfony.v2_8.route_name_test.test_resource_to_uri_mapping.json index f6586cf06a..2e22ef9f84 100644 --- a/tests/snapshots/tests.integrations.symfony.v2_8.route_name_test.test_resource_to_uri_mapping.json +++ b/tests/snapshots/tests.integrations.symfony.v2_8.route_name_test.test_resource_to_uri_mapping.json @@ -12,6 +12,7 @@ "_dd.p.tid": "6660aaff00000000", "component": "symfony", "http.method": "GET", + "http.route": "/", "http.status_code": "200", "http.url": "http://localhost/app.php?key=value&", "runtime-id": "4b578cb2-1f1d-441e-aacb-a4aaff240713", diff --git a/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_failure.json b/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_failure.json index bea7a584f0..4341464161 100644 --- a/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_failure.json +++ b/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_failure.json @@ -12,6 +12,7 @@ "_dd.p.tid": "67376acd00000000", "component": "symfony", "http.method": "GET", + "http.route": "/lucky/fail", "http.status_code": "200", "http.url": "http://localhost/lucky/fail", "runtime-id": "ec06d36e-1a6e-48f5-a627-c724d35f765b", diff --git a/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_success.json b/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_success.json index 611c454674..5769a83c09 100644 --- a/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_success.json +++ b/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_success.json @@ -12,6 +12,7 @@ "_dd.p.tid": "6737688900000000", "component": "symfony", "http.method": "GET", + "http.route": "/lucky/number", "http.status_code": "200", "http.url": "http://localhost/lucky/number", "runtime-id": "5fe9f332-5cdf-4438-a2c1-35f9245e4015", diff --git a/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_with_tracer_disabled_on_consume.json b/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_with_tracer_disabled_on_consume.json index fc9a24837c..d9c5955b2e 100644 --- a/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_with_tracer_disabled_on_consume.json +++ b/tests/snapshots/tests.integrations.symfony.v6_2.messenger_test.test_async_with_tracer_disabled_on_consume.json @@ -12,6 +12,7 @@ "_dd.p.tid": "6737607d00000000", "component": "symfony", "http.method": "GET", + "http.route": "/lucky/number", "http.status_code": "200", "http.url": "http://localhost/lucky/number", "runtime-id": "f05a51bb-8120-4e60-8705-ccc45d60b1c3", diff --git a/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_failure.json b/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_failure.json index 01fc32da5f..6f4f95e3d1 100644 --- a/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_failure.json +++ b/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_failure.json @@ -12,6 +12,7 @@ "_dd.p.tid": "67376d6700000000", "component": "symfony", "http.method": "GET", + "http.route": "/lucky/fail", "http.status_code": "200", "http.url": "http://localhost/lucky/fail", "runtime-id": "34c72fce-60c5-4a66-b562-44064d3104ba", diff --git a/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_success.json b/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_success.json index 6871aa82b8..8656fbfb2f 100644 --- a/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_success.json +++ b/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_success.json @@ -12,6 +12,7 @@ "_dd.p.tid": "67376c0a00000000", "component": "symfony", "http.method": "GET", + "http.route": "/lucky/number", "http.status_code": "200", "http.url": "http://localhost/lucky/number", "runtime-id": "1bbc4547-ce88-419f-b529-961bc1522710", diff --git a/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_with_tracer_disabled_on_consume.json b/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_with_tracer_disabled_on_consume.json index 0d636c332a..619efd5921 100644 --- a/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_with_tracer_disabled_on_consume.json +++ b/tests/snapshots/tests.integrations.symfony.v7_0.messenger_test.test_async_with_tracer_disabled_on_consume.json @@ -12,6 +12,7 @@ "_dd.p.tid": "673760aa00000000", "component": "symfony", "http.method": "GET", + "http.route": "/lucky/number", "http.status_code": "200", "http.url": "http://localhost/lucky/number", "runtime-id": "99fe2e1b-f085-435b-8e4a-909cfe1eeb25",