Skip to content

Commit

Permalink
Implement http.route for Yii
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomartinezbernardo committed Dec 19, 2023
1 parent b58702a commit 4d6dbc2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Integrations/Integrations/Yii/YiiIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function (SpanData $span, $args) use (&$firstController, $service) {
);

$rootSpan->meta['app.route.path'] = $routePath;
$rootSpan->meta[Tag::HTTP_ROUTE] = $routePath;

if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) {
$resourceName = \str_replace(
Expand Down
1 change: 1 addition & 0 deletions tests/Frameworks/Yii/Version_2_0/config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'simple' => 'simple/index',
'simple_view' => 'simple/view',
'error' => 'simple/error',
'parameterized/<value>' => 'simple/parameterized',
'homes/<state>/<city>/<neighborhood>' => 'homes/view',
'forum/<state>/<city>/<neighborhood>' => 'forum/module/view',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function actionError()
{
throw new \Exception('datadog');
}

public function actionParameterized($value)
{
return 'Hello ' . $value;
}
}
47 changes: 47 additions & 0 deletions tests/Integrations/Yii/V2_0/CommonScenariosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function provideSpecs()
Tag::HTTP_STATUS_CODE => '200',
'app.endpoint' => 'app\controllers\SimpleController::actionIndex',
'app.route.path' => '/simple',
Tag::HTTP_ROUTE => '/simple',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
])->withChildren([
Expand Down Expand Up @@ -96,6 +97,7 @@ public function provideSpecs()
Tag::HTTP_STATUS_CODE => '200',
'app.endpoint' => 'app\controllers\SimpleController::actionView',
'app.route.path' => '/simple_view',
Tag::HTTP_ROUTE => '/simple_view',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
])->withChildren([
Expand Down Expand Up @@ -142,6 +144,7 @@ public function provideSpecs()
Tag::HTTP_STATUS_CODE => '500',
'app.endpoint' => 'app\controllers\SimpleController::actionError',
'app.route.path' => '/error',
Tag::HTTP_ROUTE => '/error',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
])
Expand Down Expand Up @@ -201,6 +204,50 @@ public function provideSpecs()
]),
]),
],
'A GET request to a route with a parameter' => [
SpanAssertion::build(
'web.request',
'yii2_test_app',
'web',
'GET /parameterized/?'
)->withExactTags([
Tag::HTTP_METHOD => 'GET',
Tag::HTTP_URL => 'http://localhost:9999/parameterized/paramValue',
Tag::HTTP_STATUS_CODE => '200',
'app.endpoint' => 'app\controllers\SimpleController::actionParameterized',
'app.route.path' => '/parameterized/:value',
Tag::HTTP_ROUTE => '/parameterized/:value',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
])->withChildren([
SpanAssertion::build(
'yii\web\Application.run',
'yii2_test_app',
Type::WEB_SERVLET,
'yii\web\Application.run'
)->withExactTags([
Tag::COMPONENT => "yii",
])->withChildren([
SpanAssertion::build(
'yii\web\Application.runAction',
'yii2_test_app',
Type::WEB_SERVLET,
'simple/parameterized'
)->withExactTags([
Tag::COMPONENT => "yii",
])->withChildren([
SpanAssertion::build(
'app\controllers\SimpleController.runAction',
'yii2_test_app',
Type::WEB_SERVLET,
'parameterized'
)->withExactTags([
Tag::COMPONENT => "yii",
]),
]),
]),
]),
],
]
);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Integrations/Yii/V2_0/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testGet()
Tag::HTTP_URL => 'http://localhost:9999/forum/new-york/new-york/manhattan?key=value&<redacted>',
Tag::HTTP_STATUS_CODE => '200',
'app.route.path' => '/forum/:state/:city/:neighborhood',
Tag::HTTP_ROUTE => '/forum/:state/:city/:neighborhood',
'app.endpoint' => 'app\modules\forum\controllers\ModuleController::actionView',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
Expand Down
1 change: 1 addition & 0 deletions tests/Integrations/Yii/V2_0/ParameterizedRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testGet()
Tag::HTTP_URL => 'http://localhost:9999/homes/new-york/new-york/manhattan?key=value&<redacted>',
Tag::HTTP_STATUS_CODE => '200',
'app.route.path' => '/homes/:state/:city/:neighborhood',
Tag::HTTP_ROUTE => '/homes/:state/:city/:neighborhood',
'app.endpoint' => 'app\controllers\HomesController::actionView',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
Expand Down
1 change: 1 addition & 0 deletions tests/Integrations/Yii/V2_0/YiiDetailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function testRootIndexRoute()
Tag::HTTP_URL => 'http://localhost:9999/site/index',
Tag::HTTP_STATUS_CODE => '200',
'app.route.path' => '/site/index',
Tag::HTTP_ROUTE => '/site/index',
'app.endpoint' => 'app\controllers\SiteController::actionIndex',
Tag::SPAN_KIND => "server",
Tag::COMPONENT => "yii",
Expand Down

0 comments on commit 4d6dbc2

Please sign in to comment.