From bf900b402229ef95a5deb395a04286a9c4733841 Mon Sep 17 00:00:00 2001 From: Alexandre Choura Date: Wed, 20 Dec 2023 15:58:17 +0100 Subject: [PATCH] Remove controller's hook after execution --- .../Symfony/SymfonyIntegration.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Integrations/Integrations/Symfony/SymfonyIntegration.php b/src/Integrations/Integrations/Symfony/SymfonyIntegration.php index fc59842f48..e044555317 100644 --- a/src/Integrations/Integrations/Symfony/SymfonyIntegration.php +++ b/src/Integrations/Integrations/Symfony/SymfonyIntegration.php @@ -2,6 +2,7 @@ namespace DDTrace\Integrations\Symfony; +use DDTrace\HookData; use DDTrace\Integrations\Drupal\DrupalIntegration; use DDTrace\Integrations\Integration; use DDTrace\SpanData; @@ -11,6 +12,7 @@ use DDTrace\Util\Versions; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelEvents; +use function DDTrace\install_hook; class SymfonyIntegration extends Integration { @@ -448,27 +450,32 @@ function (SpanData $span, $args, $response) use ($integration) { if (\strpos($controllerName, '::') > 0) { list($class, $method) = \explode('::', $controllerName); if (isset($class, $method)) { - \DDTrace\trace_method( - $class, - $method, - function (SpanData $span) use ($controllerName, $integration) { + \DDTrace\install_hook( + "$class::$method", + function (HookData $hook) use ($controllerName, $integration) { + $span = $hook->span(); $span->name = 'symfony.controller'; $span->resource = $controllerName; $span->type = Type::WEB_SERVLET; $span->service = \ddtrace_config_app_name($integration->frameworkPrefix); $span->meta[Tag::COMPONENT] = SymfonyIntegration::NAME; + + \DDTrace\remove_hook($hook->id); } ); } } else { - \DDTrace\trace_function( - $controllerName, - function (SpanData $span) use ($controllerName, $integration) { + \DDTrace\install_hook( + "$controllerName", + function (HookData $hook) use ($controllerName, $integration) { + $span = $hook->span(); $span->name = 'symfony.controller'; $span->resource = $controllerName; $span->type = Type::WEB_SERVLET; $span->service = \ddtrace_config_app_name($integration->frameworkPrefix); $span->meta[Tag::COMPONENT] = SymfonyIntegration::NAME; + + \DDTrace\remove_hook($hook->id); } ); }