Skip to content

Commit 972de2d

Browse files
committed
tests: Add testSilencedSpansAreDropped for Symfony CLI Tests
1 parent da7d5e8 commit 972de2d

12 files changed

Lines changed: 493 additions & 0 deletions

src/DDTrace/Integrations/Symfony/SymfonyIntegration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ function (HookData $hook) use ($controllerName, $integration) {
547547
*/
548548
foreach (['Symfony\Component\Console\Terminal::hasSttyAvailable', 'Symfony\Component\Console\Helper\QuestionHelper::isInteractiveInput'] as $method) {
549549
\DDTrace\install_hook($method, function (HookData $hook) {
550+
$hook->data = false;
550551
\DDTrace\active_stack()->spanCreationObservers[] = function (SpanData $span) use ($hook) {
551552
if ($hook->data) {
552553
return false;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Command;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Terminal;
10+
11+
#[AsCommand(
12+
name: 'app:stty'
13+
)]
14+
class SttyCommand extends Command
15+
{
16+
protected function execute(InputInterface $input, OutputInterface $output): int
17+
{
18+
$terminal = new Terminal();
19+
$terminal->hasSttyAvailable();
20+
21+
return Command::SUCCESS;
22+
}
23+
}

tests/Frameworks/Symfony/Version_4_4/src/Command/SttyCommand.php

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Terminal;
9+
10+
class SttyCommand extends Command
11+
{
12+
protected static $defaultName = 'app:stty';
13+
14+
protected function execute(InputInterface $input, OutputInterface $output): int
15+
{
16+
$terminal = new Terminal();
17+
$terminal->hasSttyAvailable();
18+
19+
return Command::SUCCESS;
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Terminal;
9+
10+
class SttyCommand extends Command
11+
{
12+
protected static $defaultName = 'app:stty';
13+
14+
protected function execute(InputInterface $input, OutputInterface $output): int
15+
{
16+
$terminal = new Terminal();
17+
$terminal->hasSttyAvailable();
18+
19+
return Command::SUCCESS;
20+
}
21+
}

tests/Integrations/CLI/Symfony/V4_4/CommonScenariosTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,16 @@ public function testLongRunningCommandWithoutRootSpan()
160160
[]
161161
);
162162
}
163+
164+
public function testSilencedSpansAreDropped()
165+
{
166+
list($traces) = $this->inCli(static::getConsoleScript(), [
167+
'DD_TRACE_CLI_ENABLED' => 'true',
168+
'DD_TRACE_GENERATE_ROOT_SPAN' => 'true',
169+
'DD_TRACE_AUTO_FLUSH_ENABLED' => 'true',
170+
'DD_TRACE_EXEC_ENABLED' => 'true',
171+
], [], 'app:stty');
172+
173+
$this->snapshotFromTraces($traces);
174+
}
163175
}

tests/Integrations/CLI/Symfony/V5_2/CommonScenariosTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,16 @@ public function testLongRunningCommandWithoutRootSpan()
160160
[]
161161
);
162162
}
163+
164+
public function testSilencedSpansAreDropped()
165+
{
166+
list($traces) = $this->inCli(static::getConsoleScript(), [
167+
'DD_TRACE_CLI_ENABLED' => 'true',
168+
'DD_TRACE_GENERATE_ROOT_SPAN' => 'true',
169+
'DD_TRACE_AUTO_FLUSH_ENABLED' => 'true',
170+
'DD_TRACE_EXEC_ENABLED' => 'true',
171+
], [], 'app:stty');
172+
173+
$this->snapshotFromTraces($traces);
174+
}
163175
}

tests/Integrations/CLI/Symfony/V6_2/CommonScenariosTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,16 @@ public function testLongRunningCommandWithoutRootSpan()
165165
[]
166166
);
167167
}
168+
169+
public function testSilencedSpansAreDropped()
170+
{
171+
list($traces) = $this->inCli(static::getConsoleScript(), [
172+
'DD_TRACE_CLI_ENABLED' => 'true',
173+
'DD_TRACE_GENERATE_ROOT_SPAN' => 'true',
174+
'DD_TRACE_AUTO_FLUSH_ENABLED' => 'true',
175+
'DD_TRACE_EXEC_ENABLED' => 'true',
176+
], [], 'app:stty');
177+
178+
$this->snapshotFromTraces($traces);
179+
}
168180
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[[
2+
{
3+
"name": "console",
4+
"service": "console",
5+
"resource": "console",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "cli",
10+
"meta": {
11+
"_dd.p.dm": "0",
12+
"_dd.p.tid": "67dd820c00000000",
13+
"runtime-id": "70a85d5f-2b3f-45ee-8fa6-493f858df4d9"
14+
},
15+
"metrics": {
16+
"_dd.agent_psr": 1,
17+
"_sampling_priority_v1": 1
18+
}
19+
},
20+
{
21+
"name": "command_execution",
22+
"service": "console",
23+
"resource": "stty",
24+
"trace_id": 0,
25+
"span_id": 2,
26+
"parent_id": 1,
27+
"type": "system",
28+
"meta": {
29+
"cmd.exec": "[\"stty\",\"-a\"]",
30+
"cmd.exit_code": "0",
31+
"component": "subprocess"
32+
}
33+
},
34+
{
35+
"name": "symfony.httpkernel.kernel.boot",
36+
"service": "symfony",
37+
"resource": "App\\Kernel",
38+
"trace_id": 0,
39+
"span_id": 3,
40+
"parent_id": 1,
41+
"type": "web",
42+
"meta": {
43+
"_dd.base_service": "console",
44+
"component": "symfony"
45+
}
46+
},
47+
{
48+
"name": "command_execution",
49+
"service": "console",
50+
"resource": "sh",
51+
"trace_id": 0,
52+
"span_id": 4,
53+
"parent_id": 1,
54+
"type": "system",
55+
"meta": {
56+
"cmd.shell": "stty -g",
57+
"component": "subprocess"
58+
}
59+
},
60+
{
61+
"name": "symfony.console.command",
62+
"service": "symfony",
63+
"resource": "symfony.console.command",
64+
"trace_id": 0,
65+
"span_id": 5,
66+
"parent_id": 1,
67+
"type": "cli",
68+
"meta": {
69+
"_dd.base_service": "console",
70+
"component": "symfony"
71+
}
72+
},
73+
{
74+
"name": "symfony.console.command.run",
75+
"service": "symfony",
76+
"resource": "app:stty",
77+
"trace_id": 0,
78+
"span_id": 6,
79+
"parent_id": 1,
80+
"type": "cli",
81+
"meta": {
82+
"_dd.base_service": "console",
83+
"component": "symfony",
84+
"symfony.console.command.class": "App\\Command\\SttyCommand"
85+
}
86+
},
87+
{
88+
"name": "symfony.console.terminate",
89+
"service": "symfony",
90+
"resource": "symfony.console.terminate",
91+
"trace_id": 0,
92+
"span_id": 7,
93+
"parent_id": 1,
94+
"type": "cli",
95+
"meta": {
96+
"_dd.base_service": "console",
97+
"component": "symfony"
98+
}
99+
}]]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[[
2+
{
3+
"name": "console",
4+
"service": "console",
5+
"resource": "console",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "cli",
10+
"meta": {
11+
"_dd.p.dm": "0",
12+
"_dd.p.tid": "67dd847d00000000",
13+
"runtime-id": "912cfa64-a941-41e9-a07c-4b770d603d12"
14+
},
15+
"metrics": {
16+
"_dd.agent_psr": 1,
17+
"_sampling_priority_v1": 1
18+
}
19+
},
20+
{
21+
"name": "command_execution",
22+
"service": "console",
23+
"resource": "sh",
24+
"trace_id": 0,
25+
"span_id": 2,
26+
"parent_id": 1,
27+
"type": "system",
28+
"meta": {
29+
"cmd.exit_code": "0",
30+
"cmd.shell": "stty -a | grep columns",
31+
"component": "subprocess"
32+
}
33+
},
34+
{
35+
"name": "symfony.httpkernel.kernel.boot",
36+
"service": "symfony",
37+
"resource": "App\\Kernel",
38+
"trace_id": 0,
39+
"span_id": 3,
40+
"parent_id": 1,
41+
"type": "web",
42+
"meta": {
43+
"_dd.base_service": "console",
44+
"component": "symfony"
45+
}
46+
},
47+
{
48+
"name": "symfony.console.command",
49+
"service": "symfony",
50+
"resource": "symfony.console.command",
51+
"trace_id": 0,
52+
"span_id": 4,
53+
"parent_id": 1,
54+
"type": "cli",
55+
"meta": {
56+
"_dd.base_service": "console",
57+
"component": "symfony"
58+
}
59+
},
60+
{
61+
"name": "symfony.console.command.run",
62+
"service": "symfony",
63+
"resource": "app:stty",
64+
"trace_id": 0,
65+
"span_id": 5,
66+
"parent_id": 1,
67+
"type": "cli",
68+
"meta": {
69+
"_dd.base_service": "console",
70+
"component": "symfony",
71+
"symfony.console.command.class": "App\\Command\\SttyCommand"
72+
}
73+
},
74+
{
75+
"name": "symfony.console.terminate",
76+
"service": "symfony",
77+
"resource": "symfony.console.terminate",
78+
"trace_id": 0,
79+
"span_id": 6,
80+
"parent_id": 1,
81+
"type": "cli",
82+
"meta": {
83+
"_dd.base_service": "console",
84+
"component": "symfony"
85+
}
86+
}]]

0 commit comments

Comments
 (0)