Skip to content

Commit 1111e80

Browse files
authored
fix(laravel): use route URI instead of unnamed_route in resource name (#3761)
When DD_HTTP_SERVER_ROUTE_BASED_NAMING is enabled (default), routes defined without a ->name() call produced resources like: App\Http\Controllers\FooController@bar unnamed_route This was unhelpful and inconsistent with named routes. For unnamed routes, fall back to `{HTTP_METHOD} {route_uri}` (e.g. `GET error`), which matches the format customers already see for named routes and gives a meaningful, actionable resource name. Named routes are unaffected. Fixes APMS-18982
1 parent 856068a commit 1111e80

21 files changed

Lines changed: 28 additions & 22 deletions

File tree

src/DDTrace/Integrations/Laravel/LaravelIntegration.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ static function ($This, $scope, $args, $route) {
122122
$routeName = self::normalizeRouteName($route->getName());
123123

124124
if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) {
125-
$rootSpan->resource = $route->getActionName() . ' ' . $routeName;
125+
if ($routeName !== self::UNNAMED_ROUTE) {
126+
$rootSpan->resource = $route->getActionName() . ' ' . $routeName;
127+
} elseif (method_exists($route, 'uri')) {
128+
$rootSpan->resource = $route->getActionName() . ' ' . $route->uri();
129+
} else {
130+
$rootSpan->resource = $route->getActionName() . ' ' . self::UNNAMED_ROUTE;
131+
}
126132
}
127133

128134
$rootSpan->meta['laravel.route.name'] = $routeName;

tests/Integrations/Laravel/V8_x/RouteCachingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testNotCached()
3636
'laravel.request',
3737
'Laravel',
3838
'web',
39-
'App\Http\Controllers\RouteCachingController@unnamed unnamed_route'
39+
'App\Http\Controllers\RouteCachingController@unnamed unnamed-route'
4040
)
4141
->withExactTags([
4242
'laravel.route.name' => 'unnamed_route',
@@ -84,7 +84,7 @@ public function testCached()
8484
'laravel.request',
8585
'Laravel',
8686
'web',
87-
'App\Http\Controllers\RouteCachingController@unnamed unnamed_route'
87+
'App\Http\Controllers\RouteCachingController@unnamed unnamed-route'
8888
)
8989
->withExactTags([
9090
'laravel.route.name' => 'unnamed_route',

tests/snapshots/tests.integrations.laravel.apigw_test.test_laravel_inferred_proxy_exception.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{
3131
"name": "laravel.request",
3232
"service": "my_service",
33-
"resource": "App\\Http\\Controllers\\CommonSpecsController@error unnamed_route",
33+
"resource": "App\\Http\\Controllers\\CommonSpecsController@error error",
3434
"trace_id": 0,
3535
"span_id": 2,
3636
"parent_id": 1,

tests/snapshots/tests.integrations.laravel.latest.common_scenarios_test.test_scenario_get_with_exception.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "laravel.request",
44
"service": "my_service",
5-
"resource": "App\\Http\\Controllers\\CommonSpecsController@error unnamed_route",
5+
"resource": "App\\Http\\Controllers\\CommonSpecsController@error error",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 5879388483676493807,

tests/snapshots/tests.integrations.laravel.latest.common_scenarios_test.test_scenario_get_with_view.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "laravel.request",
44
"service": "my_service",
5-
"resource": "App\\Http\\Controllers\\CommonSpecsController@simple_view unnamed_route",
5+
"resource": "App\\Http\\Controllers\\CommonSpecsController@simple_view simple_view",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 13950427361689200115,

tests/snapshots/tests.integrations.laravel.octane.apigw_test.test_inferred_proxy_exception.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
{
3030
"name": "laravel.request",
3131
"service": "swoole_test_app",
32-
"resource": "App\\Http\\Controllers\\CommonSpecsController@error unnamed_route",
32+
"resource": "App\\Http\\Controllers\\CommonSpecsController@error error",
3333
"trace_id": 0,
3434
"span_id": 2,
3535
"parent_id": 1,

tests/snapshots/tests.integrations.laravel.v10_x.common_scenarios_test.test_scenario_get_with_exception.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "laravel.request",
44
"service": "my_service",
5-
"resource": "App\\Http\\Controllers\\CommonSpecsController@error unnamed_route",
5+
"resource": "App\\Http\\Controllers\\CommonSpecsController@error error",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 14785377647724168590,

tests/snapshots/tests.integrations.laravel.v10_x.common_scenarios_test.test_scenario_get_with_view.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "laravel.request",
44
"service": "my_service",
5-
"resource": "App\\Http\\Controllers\\CommonSpecsController@simple_view unnamed_route",
5+
"resource": "App\\Http\\Controllers\\CommonSpecsController@simple_view simple_view",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 833116231812134410,

tests/snapshots/tests.integrations.laravel.v11_x.common_scenarios_test.test_scenario_get_with_exception.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "laravel.request",
44
"service": "my_service",
5-
"resource": "App\\Http\\Controllers\\CommonSpecsController@error unnamed_route",
5+
"resource": "App\\Http\\Controllers\\CommonSpecsController@error error",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 7417571401826106684,

tests/snapshots/tests.integrations.laravel.v11_x.common_scenarios_test.test_scenario_get_with_view.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "laravel.request",
44
"service": "my_service",
5-
"resource": "App\\Http\\Controllers\\CommonSpecsController@simple_view unnamed_route",
5+
"resource": "App\\Http\\Controllers\\CommonSpecsController@simple_view simple_view",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 11570399397149531429,

0 commit comments

Comments
 (0)