Skip to content

Commit 2edad0a

Browse files
Julian-Louiscataphract
authored andcommitted
Add http.route tag to SymfonyIntegration.php
1 parent 620af85 commit 2edad0a

32 files changed

+121
-17
lines changed

appsec/tests/integration/src/docker/php/build_dev_php.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ EOD
8080
chmod +x /tmp/apxs_wrapper
8181
}
8282

83+
function run_dsymutil {
84+
if [[ $(uname) != Darwin ]] then
85+
return
86+
fi
87+
local readonly dir=$1 exe=
88+
find "$dir" -type f -exec test -x '{}' \; -print | while read -r exe; do
89+
if ! grep -q '^#!' "$exe"; then
90+
local readonly dSYM_DIR="${exe}.dSYM"
91+
if [[ ! -d $dSYM_DIR ]]; then
92+
dsymutil "$exe"
93+
fi
94+
fi
95+
done
96+
}
97+
8398
function get_xdebug_version {
8499
local -r version=$1
85100
local readonly version_id=$(php_version_id $version)
@@ -294,6 +309,7 @@ function build_php {
294309
make install-sapi || true
295310
make install-binaries install-headers install-modules install-programs install-build
296311

312+
run_dsymutil "$prefix_dir"
297313
rm -rf "$build_dir"
298314
cd -
299315
}
@@ -462,11 +478,12 @@ function install_xdebug {
462478
"$php_prefix/bin/phpize"
463479
mkdir -p "$build_dir"
464480
cd "$build_dir"
465-
"$xdebug_source_dir/configure" "--with-php-config=$php_prefix/bin/php-config"
481+
CFLAGS="$CFLAGS -ggdb" "$xdebug_source_dir/configure" "--with-php-config=$php_prefix/bin/php-config"
466482
make -j
467483
make install
468484
cd -
469485

486+
run_dsymutil "$php_prefix/lib"
470487
rm -rf "$build_dir"
471488
}
472489

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
framework:
22
test: true
33
session:
4-
storage_id: session.storage.mock_file
4+
storage_factory_id: session.storage.factory.mock_file

appsec/tests/integration/src/test/www/symfony62/src/Controller/HomeController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ public function homeAction(Request $request)
2121
);
2222
}
2323

24-
/**
25-
* @Route("/dynamic-path/{param01}", name="dynamic-path")
26-
*/
27-
public function dynamicAction(Request $request)
24+
#[Route("/dynamic-path/{param01}")]
25+
public function dynamicAction(Request $request, string $param01)
2826
{
2927
return new Response(
30-
'Hi!'
28+
"Hi $param01!"
3129
);
3230
}
3331
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ services:
249249
test-agent:
250250
image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:latest
251251
ports:
252-
- "127.0.0.1:9126:8126"
252+
- "9126:9126"
253253
volumes:
254254
- ./tests/snapshots:/snapshots
255255
environment:

src/DDTrace/Integrations/Symfony/SymfonyIntegration.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use DDTrace\Type;
1111
use DDTrace\Util\Normalizer;
1212
use Symfony\Component\HttpFoundation\Request;
13+
use Symfony\Component\HttpKernel\Event\ControllerEvent;
1314
use Symfony\Component\HttpKernel\KernelEvents;
15+
use Symfony\Component\Routing\Route;
1416

1517
class SymfonyIntegration extends Integration
1618
{
@@ -307,6 +309,42 @@ function ($This, $scope, $args) use ($integration) {
307309
}
308310
);
309311

312+
\DDTrace\trace_method(
313+
'Symfony\Component\EventDispatcher\EventDispatcher',
314+
'dispatch',
315+
function (SpanData $span, $args) {
316+
$event = $args[0];
317+
318+
if (!($event instanceof ControllerEvent)) {
319+
return;
320+
}
321+
322+
$request = $event->getRequest();
323+
$controller = $event->getController()[0];
324+
325+
if (!property_exists($controller, 'container')) {
326+
return;
327+
}
328+
329+
$rc = new \ReflectionClass(get_class($controller));
330+
$container = $rc->getProperty('container');
331+
$container->setAccessible(true);
332+
$container = $container->getValue($controller);
333+
334+
$router = $container->get('router');
335+
$routeName = $request->attributes->get('_route');
336+
337+
$routeCollection = $router->getRouteCollection();
338+
/** @var Route $route */
339+
$route = $routeCollection->get($routeName);
340+
if (!isset($route)) {
341+
return;
342+
}
343+
$root_span = \DDTrace\root_span();
344+
$root_span->meta[Tag::HTTP_ROUTE] = $route->getPath();
345+
}
346+
);
347+
310348
$this->loadSymfony($this);
311349

312350
return Integration::LOADED;
@@ -394,7 +432,7 @@ function (SpanData $span, $args, $response) use ($integration) {
394432
$parameters = $request->get('_route_params');
395433
if (!empty($parameters) &&
396434
is_array($parameters) &&
397-
function_exists('\datadog\appsec\push_address')) {
435+
function_exists('datadog\appsec\push_address')) {
398436
\datadog\appsec\push_address("server.request.path_params", $parameters);
399437
}
400438

tests/Common/TracerTestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public function tracesFromWebRequest($fn, $tracer = null, callable $until = null
310310
// Clearing existing dumped file
311311
$this->resetRequestDumper();
312312

313-
// The we server has to be configured to send traces to the provided requests dumper.
313+
// The web server has to be configured to send traces to the provided requests dumper.
314314
$fn($tracer);
315315

316316
self::putEnv('DD_TRACE_SHUTDOWN_TIMEOUT');

tests/Common/WebFrameworkTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,18 @@ protected static function getInis()
141141
// The following values should be made configurable from the outside. I could not get env XDEBUG_CONFIG
142142
// to work setting it both in docker-compose.yml and in `getEnvs()` above, but that should be the best
143143
// option.
144+
'xdebug.start_with_request' => 'yes',
145+
146+
// 2
144147
'xdebug.remote_enable' => 1,
145148
'xdebug.remote_host' => 'host.docker.internal',
146149
'xdebug.remote_autostart' => 1,
150+
// 'xdebug.remote_log' => '/tmp/xdebug.log',
151+
152+
// 3
153+
'xdebug.mode' => 'develop,debug',
154+
'xdebug.client_host' => 'host.docker.internal',
155+
// 'xdebug.log' => '/tmp/xdebug.log',
147156
] + ($enableOpcache ? ["zend_extension" => "opcache.so"] : []);
148157
}
149158

tests/Frameworks/Symfony/Version_6_2/src/Controller/CommonScenariosController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
class CommonScenariosController extends AbstractController
1111
{
1212

13-
/**
14-
* @Route("/simple", name="simple")
15-
*/
13+
#[Route("/simple", name:"simple")]
1614
public function simpleAction(Request $request)
1715
{
1816
// replace this example code with whatever you need
@@ -21,9 +19,7 @@ public function simpleAction(Request $request)
2119
);
2220
}
2321

24-
/**
25-
* @Route("/simple_view", name="simple_view")
26-
*/
22+
#[Route("/simple_view", name:"simple_view")]
2723
public function simpleViewAction(Request $request)
2824
{
2925
// replace this example code with whatever you need
@@ -43,9 +39,9 @@ public function dynamicWithOptionalsAction($param01, $param02)
4339
}
4440

4541
/**
46-
* @Route("/error", name="error")
4742
* @throws \Exception
4843
*/
44+
#[Route("/error", name:"error")]
4945
public function errorAction(Request $request)
5046
{
5147
throw new \Exception('An exception occurred');

tests/Integrations/Symfony/V3_0/CommonScenariosTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function provideSpecs()
4242
)->withExactTags([
4343
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple?key=value&<redacted>',
4748
'http.status_code' => '200',
@@ -79,6 +80,7 @@ public function provideSpecs()
7980
)->withExactTags([
8081
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleViewAction',
8182
'symfony.route.name' => 'simple_view',
83+
'http.route' => '/simple_view',
8284
'http.method' => 'GET',
8385
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
8486
'http.status_code' => '200',
@@ -125,6 +127,7 @@ public function provideSpecs()
125127
)->withExactTags([
126128
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@errorAction',
127129
'symfony.route.name' => 'error',
130+
'http.route' => '/error',
128131
'http.method' => 'GET',
129132
'http.url' => 'http://localhost/error?key=value&<redacted>',
130133
'http.status_code' => '500',

tests/Integrations/Symfony/V3_0/TraceSearchConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testScenario()
4242
)->withExactTags([
4343
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple',
4748
'http.status_code' => '200',

tests/Integrations/Symfony/V3_3/CommonScenariosTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function provideSpecs()
4242
)->withExactTags([
4343
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple?key=value&<redacted>',
4748
'http.status_code' => '200',
@@ -80,6 +81,7 @@ public function provideSpecs()
8081
)->withExactTags([
8182
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleViewAction',
8283
'symfony.route.name' => 'simple_view',
84+
'http.route' => '/simple_view',
8385
'http.method' => 'GET',
8486
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
8587
'http.status_code' => '200',
@@ -127,6 +129,7 @@ public function provideSpecs()
127129
)->withExactTags([
128130
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@errorAction',
129131
'symfony.route.name' => 'error',
132+
'http.route' => '/error',
130133
'http.method' => 'GET',
131134
'http.url' => 'http://localhost/error?key=value&<redacted>',
132135
'http.status_code' => '500',

tests/Integrations/Symfony/V3_3/TraceSearchConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testScenario()
4242
)->withExactTags([
4343
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple',
4748
'http.status_code' => '200',

tests/Integrations/Symfony/V3_4/AutofinishedTracesSymfony34Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testEndpointThatExitsWithNoProcess()
3636
)->withExactTags([
3737
'symfony.route.action' => 'AppBundle\Controller\HomeController@actionBeingTerminatedByExit',
3838
'symfony.route.name' => 'terminated_by_exit',
39+
'http.route' => '/terminated_by_exit',
3940
'http.method' => 'GET',
4041
'http.url' => 'http://localhost/terminated_by_exit',
4142
'http.status_code' => '200',

tests/Integrations/Symfony/V3_4/CommonScenariosTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function provideSpecs()
4949
)->withExactTags([
5050
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
5151
'symfony.route.name' => 'simple',
52+
'http.route' => '/simple',
5253
'http.method' => 'GET',
5354
'http.url' => 'http://localhost/simple?key=value&<redacted>',
5455
'http.status_code' => '200',
@@ -87,6 +88,7 @@ public function provideSpecs()
8788
)->withExactTags([
8889
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleViewAction',
8990
'symfony.route.name' => 'simple_view',
91+
'http.route' => '/simple_view',
9092
'http.method' => 'GET',
9193
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
9294
'http.status_code' => '200',
@@ -136,6 +138,7 @@ public function provideSpecs()
136138
->withExactTags([
137139
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@errorAction',
138140
'symfony.route.name' => 'error',
141+
'http.route' => '/error',
139142
'http.method' => 'GET',
140143
'http.url' => 'http://localhost/error?key=value&<redacted>',
141144
'http.status_code' => '500',

tests/Integrations/Symfony/V3_4/TemplateEnginesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function testAlternateTemplatingEngine()
2929
)->withExactTags([
3030
'symfony.route.action' => 'AppBundle\Controller\HomeController@indexAction',
3131
'symfony.route.name' => 'alternate_templating',
32+
'http.route' => '/alternate_templating',
3233
'http.method' => 'GET',
3334
'http.url' => 'http://localhost/alternate_templating',
3435
'http.status_code' => '200',

tests/Integrations/Symfony/V3_4/TraceSearchConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testScenario()
4242
)->withExactTags([
4343
'symfony.route.action' => 'AppBundle\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple',
4748
'http.status_code' => '200',

tests/Integrations/Symfony/V4_0/CommonScenariosTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function provideSpecs()
5050
)->withExactTags([
5151
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleAction',
5252
'symfony.route.name' => 'simple',
53+
'http.route' => '/simple',
5354
'http.method' => 'GET',
5455
'http.url' => 'http://localhost/simple?key=value&<redacted>',
5556
'http.status_code' => '200',
@@ -88,6 +89,7 @@ public function provideSpecs()
8889
)->withExactTags([
8990
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleViewAction',
9091
'symfony.route.name' => 'simple_view',
92+
'http.route' => '/simple_view',
9193
'http.method' => 'GET',
9294
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
9395
'http.status_code' => '200',
@@ -135,6 +137,7 @@ public function provideSpecs()
135137
)->withExactTags([
136138
'symfony.route.action' => 'App\Controller\CommonScenariosController@errorAction',
137139
'symfony.route.name' => 'error',
140+
'http.route' => '/error',
138141
'http.method' => 'GET',
139142
'http.url' => 'http://localhost/error?key=value&<redacted>',
140143
'http.status_code' => '500',

tests/Integrations/Symfony/V4_0/TraceSearchConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testScenario()
4242
)->withExactTags([
4343
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple',
4748
'http.status_code' => '200',

tests/Integrations/Symfony/V4_2/CommonScenariosTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function provideSpecs()
5050
)->withExactTags([
5151
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleAction',
5252
'symfony.route.name' => 'simple',
53+
'http.route' => '/simple',
5354
'http.method' => 'GET',
5455
'http.url' => 'http://localhost/simple?key=value&<redacted>',
5556
'http.status_code' => '200',
@@ -88,6 +89,7 @@ public function provideSpecs()
8889
)->withExactTags([
8990
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleViewAction',
9091
'symfony.route.name' => 'simple_view',
92+
'http.route' => '/simple_view',
9193
'http.method' => 'GET',
9294
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
9395
'http.status_code' => '200',
@@ -135,6 +137,7 @@ public function provideSpecs()
135137
)->withExactTags([
136138
'symfony.route.action' => 'App\Controller\CommonScenariosController@errorAction',
137139
'symfony.route.name' => 'error',
140+
'http.route' => '/error',
138141
'http.method' => 'GET',
139142
'http.url' => 'http://localhost/error?key=value&<redacted>',
140143
'http.status_code' => '500',

tests/Integrations/Symfony/V4_2/TraceSearchConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testScenario()
4242
)->withExactTags([
4343
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleAction',
4444
'symfony.route.name' => 'simple',
45+
'http.route' => '/simple',
4546
'http.method' => 'GET',
4647
'http.url' => 'http://localhost/simple',
4748
'http.status_code' => '200',

tests/Integrations/Symfony/V4_4/CommonScenariosTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function provideSpecs()
5050
)->withExactTags([
5151
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleAction',
5252
'symfony.route.name' => 'simple',
53+
'http.route' => '/simple',
5354
'http.method' => 'GET',
5455
'http.url' => 'http://localhost/simple?key=value&<redacted>',
5556
'http.status_code' => '200',
@@ -90,6 +91,7 @@ public function provideSpecs()
9091
)->withExactTags([
9192
'symfony.route.action' => 'App\Controller\CommonScenariosController@simpleViewAction',
9293
'symfony.route.name' => 'simple_view',
94+
'http.route' => '/simple_view',
9395
'http.method' => 'GET',
9496
'http.url' => 'http://localhost/simple_view?key=value&<redacted>',
9597
'http.status_code' => '200',
@@ -137,6 +139,7 @@ public function provideSpecs()
137139
)->withExactTags([
138140
'symfony.route.action' => 'App\Controller\CommonScenariosController@errorAction',
139141
'symfony.route.name' => 'error',
142+
'http.route' => '/error',
140143
'http.method' => 'GET',
141144
'http.url' => 'http://localhost/error?key=value&<redacted>',
142145
'http.status_code' => '500',

0 commit comments

Comments
 (0)