Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Instrumentation/Yii/src/YiiInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ public static function register(): void
$span = Span::fromContext($scope->context());
$actionName = $action instanceof InlineAction ? $action->actionMethod : $action->id;
$route = YiiInstrumentation::normalizeRouteName(get_class($controller), $actionName);

// Get the HTTP method from the request
$request = $controller->request;
$method = $request->getMethod();

/** @psalm-suppress ArgumentTypeCoercion */
$span->updateName($route);
// Update span name to follow OpenTelemetry HTTP naming convention: {http.method} {http.route}
$span->updateName(sprintf('%s %s', $method, $route));
$span->setAttribute(TraceAttributes::HTTP_ROUTE, $route);
},
post: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function test_success()

$attributes = $this->storage[0]->getAttributes();
$this->assertCount(1, $this->storage);
$this->assertEquals('SiteController.actionIndex', $this->storage[0]->getName());
$this->assertEquals('GET SiteController.actionIndex', $this->storage[0]->getName());
$this->assertEquals('http://example.com/site/index', $attributes->get(TraceAttributes::URL_FULL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
Expand All @@ -40,7 +40,7 @@ public function test_non_inline_action()

$attributes = $this->storage[0]->getAttributes();
$this->assertCount(1, $this->storage);
$this->assertEquals('SiteController.error', $this->storage[0]->getName());
$this->assertEquals('GET SiteController.error', $this->storage[0]->getName());
$this->assertEquals('http://example.com/site/error', $attributes->get(TraceAttributes::URL_FULL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
Expand All @@ -56,7 +56,7 @@ public function test_exception()

$attributes = $this->storage[0]->getAttributes();
$this->assertCount(1, $this->storage);
$this->assertEquals('SiteController.actionThrow', $this->storage[0]->getName());
$this->assertEquals('GET SiteController.actionThrow', $this->storage[0]->getName());
$this->assertEquals('http://example.com/site/throw', $attributes->get(TraceAttributes::URL_FULL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
Expand All @@ -82,7 +82,7 @@ public function test_parent()

$attributes = $span->getAttributes();
$this->assertCount(1, $this->storage);
$this->assertEquals('SiteController.actionIndex', $this->storage[0]->getName());
$this->assertEquals('GET SiteController.actionIndex', $this->storage[0]->getName());
$this->assertEquals('http://example.com/site/index', $attributes->get(TraceAttributes::URL_FULL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
Expand Down Expand Up @@ -165,17 +165,25 @@ private function runRequest($path)

class SiteController extends Controller
{
/**
* @return mixed
*/
public function actionIndex()
{
return \Yii::createObject([
/** @var array{class: class-string, format: string, content: string} $config */
$config = [
'class' => 'yii\web\Response',
'format' => \yii\web\Response::FORMAT_RAW,
'content' => 'hello',
]);
];

return \Yii::createObject($config);
}

/** @psalm-suppress MoreSpecificReturnType */
public function actions()
{
/** @psalm-suppress LessSpecificReturnStatement */
return [
'error' => [
'class' => 'yii\web\ErrorAction',
Expand Down
Loading