Skip to content

Commit 4d6dbc2

Browse files
Implement http.route for Yii
1 parent b58702a commit 4d6dbc2

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

src/Integrations/Integrations/Yii/YiiIntegration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function (SpanData $span, $args) use (&$firstController, $service) {
165165
);
166166

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

169170
if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) {
170171
$resourceName = \str_replace(

tests/Frameworks/Yii/Version_2_0/config/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
'simple' => 'simple/index',
6060
'simple_view' => 'simple/view',
6161
'error' => 'simple/error',
62+
'parameterized/<value>' => 'simple/parameterized',
6263
'homes/<state>/<city>/<neighborhood>' => 'homes/view',
6364
'forum/<state>/<city>/<neighborhood>' => 'forum/module/view',
6465
],

tests/Frameworks/Yii/Version_2_0/controllers/SimpleController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ public function actionError()
3030
{
3131
throw new \Exception('datadog');
3232
}
33+
34+
public function actionParameterized($value)
35+
{
36+
return 'Hello ' . $value;
37+
}
3338
}

tests/Integrations/Yii/V2_0/CommonScenariosTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function provideSpecs()
5353
Tag::HTTP_STATUS_CODE => '200',
5454
'app.endpoint' => 'app\controllers\SimpleController::actionIndex',
5555
'app.route.path' => '/simple',
56+
Tag::HTTP_ROUTE => '/simple',
5657
Tag::SPAN_KIND => "server",
5758
Tag::COMPONENT => "yii",
5859
])->withChildren([
@@ -96,6 +97,7 @@ public function provideSpecs()
9697
Tag::HTTP_STATUS_CODE => '200',
9798
'app.endpoint' => 'app\controllers\SimpleController::actionView',
9899
'app.route.path' => '/simple_view',
100+
Tag::HTTP_ROUTE => '/simple_view',
99101
Tag::SPAN_KIND => "server",
100102
Tag::COMPONENT => "yii",
101103
])->withChildren([
@@ -142,6 +144,7 @@ public function provideSpecs()
142144
Tag::HTTP_STATUS_CODE => '500',
143145
'app.endpoint' => 'app\controllers\SimpleController::actionError',
144146
'app.route.path' => '/error',
147+
Tag::HTTP_ROUTE => '/error',
145148
Tag::SPAN_KIND => "server",
146149
Tag::COMPONENT => "yii",
147150
])
@@ -201,6 +204,50 @@ public function provideSpecs()
201204
]),
202205
]),
203206
],
207+
'A GET request to a route with a parameter' => [
208+
SpanAssertion::build(
209+
'web.request',
210+
'yii2_test_app',
211+
'web',
212+
'GET /parameterized/?'
213+
)->withExactTags([
214+
Tag::HTTP_METHOD => 'GET',
215+
Tag::HTTP_URL => 'http://localhost:9999/parameterized/paramValue',
216+
Tag::HTTP_STATUS_CODE => '200',
217+
'app.endpoint' => 'app\controllers\SimpleController::actionParameterized',
218+
'app.route.path' => '/parameterized/:value',
219+
Tag::HTTP_ROUTE => '/parameterized/:value',
220+
Tag::SPAN_KIND => "server",
221+
Tag::COMPONENT => "yii",
222+
])->withChildren([
223+
SpanAssertion::build(
224+
'yii\web\Application.run',
225+
'yii2_test_app',
226+
Type::WEB_SERVLET,
227+
'yii\web\Application.run'
228+
)->withExactTags([
229+
Tag::COMPONENT => "yii",
230+
])->withChildren([
231+
SpanAssertion::build(
232+
'yii\web\Application.runAction',
233+
'yii2_test_app',
234+
Type::WEB_SERVLET,
235+
'simple/parameterized'
236+
)->withExactTags([
237+
Tag::COMPONENT => "yii",
238+
])->withChildren([
239+
SpanAssertion::build(
240+
'app\controllers\SimpleController.runAction',
241+
'yii2_test_app',
242+
Type::WEB_SERVLET,
243+
'parameterized'
244+
)->withExactTags([
245+
Tag::COMPONENT => "yii",
246+
]),
247+
]),
248+
]),
249+
]),
250+
],
204251
]
205252
);
206253
}

tests/Integrations/Yii/V2_0/ModuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testGet()
4242
Tag::HTTP_URL => 'http://localhost:9999/forum/new-york/new-york/manhattan?key=value&<redacted>',
4343
Tag::HTTP_STATUS_CODE => '200',
4444
'app.route.path' => '/forum/:state/:city/:neighborhood',
45+
Tag::HTTP_ROUTE => '/forum/:state/:city/:neighborhood',
4546
'app.endpoint' => 'app\modules\forum\controllers\ModuleController::actionView',
4647
Tag::SPAN_KIND => "server",
4748
Tag::COMPONENT => "yii",

tests/Integrations/Yii/V2_0/ParameterizedRouteTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testGet()
4242
Tag::HTTP_URL => 'http://localhost:9999/homes/new-york/new-york/manhattan?key=value&<redacted>',
4343
Tag::HTTP_STATUS_CODE => '200',
4444
'app.route.path' => '/homes/:state/:city/:neighborhood',
45+
Tag::HTTP_ROUTE => '/homes/:state/:city/:neighborhood',
4546
'app.endpoint' => 'app\controllers\HomesController::actionView',
4647
Tag::SPAN_KIND => "server",
4748
Tag::COMPONENT => "yii",

tests/Integrations/Yii/V2_0/YiiDetailsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testRootIndexRoute()
4343
Tag::HTTP_URL => 'http://localhost:9999/site/index',
4444
Tag::HTTP_STATUS_CODE => '200',
4545
'app.route.path' => '/site/index',
46+
Tag::HTTP_ROUTE => '/site/index',
4647
'app.endpoint' => 'app\controllers\SiteController::actionIndex',
4748
Tag::SPAN_KIND => "server",
4849
Tag::COMPONENT => "yii",

0 commit comments

Comments
 (0)