Skip to content

Commit

Permalink
Install Command::run hook generally
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM committed Jan 29, 2024
1 parent 8beff3e commit e79d586
Showing 1 changed file with 27 additions and 37 deletions.
64 changes: 27 additions & 37 deletions src/Integrations/Integrations/Symfony/SymfonyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,46 +248,36 @@ function ($This, $scope, $args) {
}
);

$symfonyCommandsIntegrated = [];
\DDTrace\hook_method(
\DDTrace\trace_method(
'Symfony\Component\Console\Command\Command',
'__construct',
null,
function ($This, $scope) use (&$symfonyCommandsIntegrated, $integration) {
if (isset($symfonyCommandsIntegrated[$scope])) {
return;
}

$symfonyCommandsIntegrated[$scope] = true;

\DDTrace\trace_method($scope, 'run', [
/* Commands can evidently call other commands, so allow recursion:
* > Console events are only triggered by the main command being executed.
* > Commands called by the main command will not trigger any event.
* - https://symfony.com/doc/current/components/console/events.html.
*/
'recurse' => true,
'prehook' => function (SpanData $span) use ($scope, $integration) {
if (\DDTrace\root_span() === $span) {
return false;
}
'run',
[
/* Commands can evidently call other commands, so allow recursion:
* > Console events are only triggered by the main command being executed.
* > Commands called by the main command will not trigger any event.
* - https://symfony.com/doc/current/components/console/events.html.
*/
'recurse' => true,
'prehook' => function (SpanData $span) use ($integration) {
if (\DDTrace\root_span() === $span) {
return false;
}

$namespace = \get_class($this);
if (strpos($namespace, DrupalIntegration::NAME) !== false) {
$integration->frameworkPrefix = DrupalIntegration::NAME;
} else {
$integration->frameworkPrefix = SymfonyIntegration::NAME;
}
$namespace = \get_class($this);
if (strpos($namespace, DrupalIntegration::NAME) !== false) {
$integration->frameworkPrefix = DrupalIntegration::NAME;
} else {
$integration->frameworkPrefix = SymfonyIntegration::NAME;
}

$span->name = 'symfony.console.command.run';
$span->resource = $this->getName() ?: $span->name;
$span->service = \ddtrace_config_app_name($integration->frameworkPrefix);
$span->type = Type::CLI;
$span->meta['symfony.console.command.class'] = $scope;
$span->meta[Tag::COMPONENT] = SymfonyIntegration::NAME;
}]
);
}
$span->name = 'symfony.console.command.run';
$span->resource = $this->getName() ?: $span->name;
$span->service = \ddtrace_config_app_name($integration->frameworkPrefix);
$span->type = Type::CLI;
$span->meta['symfony.console.command.class'] = get_class($this);
$span->meta[Tag::COMPONENT] = SymfonyIntegration::NAME;
}
]
);

\DDTrace\hook_method(
Expand Down

0 comments on commit e79d586

Please sign in to comment.