Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ class App
*/
protected ?Route $route = null;

/**
* Matched Route
*
* During runtime $this->route might be overwritten with the wildcard route to keep custom functions working with
* paths not declared in the Router. Keep a copy of the original matched app route.
*/
protected ?Route $matchedRoute = null;

/**
* Wildcard route
* If set, this get's executed if no other route is matched
Expand Down Expand Up @@ -716,8 +724,7 @@ public function run(Request $request, Response $response): static
$attributes = [
'url.scheme' => $request->getProtocol(),
'http.request.method' => $request->getMethod(),
// use ->match(fresh: true) to get the matched internal route, not any wildcard route
'http.route' => $this->match($request, fresh: true)?->getPath(),
'http.route' => $this->matchedRoute?->getPath(),
'http.response.status_code' => $response->getStatusCode(),
];
$this->requestDuration->record($requestDuration, $attributes);
Expand Down Expand Up @@ -761,6 +768,7 @@ private function runInternal(Request $request, Response $response): static

$method = $request->getMethod();
$route = $this->match($request);
$this->matchedRoute = $route;
$groups = ($route instanceof Route) ? $route->getGroups() : [];

if (self::REQUEST_METHOD_HEAD == $method) {
Expand Down
Loading