Skip to content

Commit 679da8e

Browse files
authored
Remove Symfony Command Hook After Execution (#2492)
* Install `Command::run` hook generally * Ensure base namespace is used
1 parent 6b2c22f commit 679da8e

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

src/Integrations/Integrations/Symfony/SymfonyIntegration.php

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -248,46 +248,36 @@ function ($This, $scope, $args) {
248248
}
249249
);
250250

251-
$symfonyCommandsIntegrated = [];
252-
\DDTrace\hook_method(
251+
\DDTrace\trace_method(
253252
'Symfony\Component\Console\Command\Command',
254-
'__construct',
255-
null,
256-
function ($This, $scope) use (&$symfonyCommandsIntegrated, $integration) {
257-
if (isset($symfonyCommandsIntegrated[$scope])) {
258-
return;
259-
}
260-
261-
$symfonyCommandsIntegrated[$scope] = true;
262-
263-
\DDTrace\trace_method($scope, 'run', [
264-
/* Commands can evidently call other commands, so allow recursion:
265-
* > Console events are only triggered by the main command being executed.
266-
* > Commands called by the main command will not trigger any event.
267-
* - https://symfony.com/doc/current/components/console/events.html.
268-
*/
269-
'recurse' => true,
270-
'prehook' => function (SpanData $span) use ($scope, $integration) {
271-
if (\DDTrace\root_span() === $span) {
272-
return false;
273-
}
253+
'run',
254+
[
255+
/* Commands can evidently call other commands, so allow recursion:
256+
* > Console events are only triggered by the main command being executed.
257+
* > Commands called by the main command will not trigger any event.
258+
* - https://symfony.com/doc/current/components/console/events.html.
259+
*/
260+
'recurse' => true,
261+
'prehook' => function (SpanData $span) use ($integration) {
262+
if (\DDTrace\root_span() === $span) {
263+
return false;
264+
}
274265

275-
$namespace = \get_class($this);
276-
if (strpos($namespace, DrupalIntegration::NAME) !== false) {
277-
$integration->frameworkPrefix = DrupalIntegration::NAME;
278-
} else {
279-
$integration->frameworkPrefix = SymfonyIntegration::NAME;
280-
}
266+
$namespace = \get_class($this);
267+
if (strpos($namespace, DrupalIntegration::NAME) !== false) {
268+
$integration->frameworkPrefix = DrupalIntegration::NAME;
269+
} else {
270+
$integration->frameworkPrefix = SymfonyIntegration::NAME;
271+
}
281272

282-
$span->name = 'symfony.console.command.run';
283-
$span->resource = $this->getName() ?: $span->name;
284-
$span->service = \ddtrace_config_app_name($integration->frameworkPrefix);
285-
$span->type = Type::CLI;
286-
$span->meta['symfony.console.command.class'] = $scope;
287-
$span->meta[Tag::COMPONENT] = SymfonyIntegration::NAME;
288-
}]
289-
);
290-
}
273+
$span->name = 'symfony.console.command.run';
274+
$span->resource = $this->getName() ?: $span->name;
275+
$span->service = \ddtrace_config_app_name($integration->frameworkPrefix);
276+
$span->type = Type::CLI;
277+
$span->meta['symfony.console.command.class'] = \get_class($this);
278+
$span->meta[Tag::COMPONENT] = SymfonyIntegration::NAME;
279+
}
280+
]
291281
);
292282

293283
\DDTrace\hook_method(

0 commit comments

Comments
 (0)