@@ -24,6 +24,8 @@ class SymfonyIntegration extends Integration
24
24
/** @var string */
25
25
public $ frameworkPrefix = SymfonyIntegration::NAME ;
26
26
27
+ public $ http_kernel_to_kernel ;
28
+
27
29
/**
28
30
* {@inheritdoc}
29
31
*/
@@ -309,42 +311,6 @@ function ($This, $scope, $args) use ($integration) {
309
311
}
310
312
);
311
313
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
-
348
314
$ this ->loadSymfony ($ this );
349
315
350
316
return Integration::LOADED ;
@@ -393,6 +359,16 @@ function (SpanData $span) use ($class, $methodname) {
393
359
);
394
360
*/
395
361
362
+ $ kernel = null ;
363
+ \DDTrace \hook_method (
364
+ 'Symfony\Component\HttpKernel\Kernel ' ,
365
+ 'getHttpKernel ' ,
366
+ null ,
367
+ function ($ object , $ scope , $ args , $ retVal ) use ($ integration ) {
368
+ $ integration ->http_kernel_to_kernel [spl_object_hash ($ retVal )] = $ object ;
369
+ }
370
+ );
371
+
396
372
\DDTrace \hook_method (
397
373
'Symfony\Component\HttpKernel\HttpKernel ' ,
398
374
'__construct ' ,
@@ -436,12 +412,23 @@ function_exists('datadog\appsec\push_address')) {
436
412
\datadog \appsec \push_address ("server.request.path_params " , $ parameters );
437
413
}
438
414
439
- $ route = $ request ->get ('_route ' );
440
- if (null !== $ route && null !== $ request ) {
415
+ $ route_name = $ request ->get ('_route ' );
416
+ if (null !== $ route_name && null !== $ request ) {
441
417
if (dd_trace_env_config ("DD_HTTP_SERVER_ROUTE_BASED_NAMING " )) {
442
- $ rootSpan ->resource = $ route ;
418
+ $ rootSpan ->resource = $ route_name ;
419
+ }
420
+ $ rootSpan ->meta ['symfony.route.name ' ] = $ route_name ;
421
+
422
+ $ kernel = $ integration ->http_kernel_to_kernel [spl_object_hash ($ this )];
423
+ if (isset ($ kernel )) {
424
+ $ container = $ kernel ->getContainer ();
425
+ $ router = $ container ->get ('router ' );
426
+ $ routeCollection = $ router ->getRouteCollection ();
427
+ $ route = $ routeCollection ->get ($ route_name );
428
+ if (isset ($ route )) {
429
+ $ rootSpan ->meta [Tag::HTTP_ROUTE ] = $ route ->getPath ();
430
+ }
443
431
}
444
- $ rootSpan ->meta ['symfony.route.name ' ] = $ route ;
445
432
}
446
433
}
447
434
);
0 commit comments