Skip to content

Commit b6645c0

Browse files
authored
Discard Laravel 7 route cache generated route names (#337)
* Discard generated route names * Add changelog entry
1 parent 41884a1 commit b6645c0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Discard Laravel 7 route cache generated route names (#337)
6+
57
## 1.7.0
68

79
- Support for Laravel 7 (#330)

src/Sentry/Laravel/EventHandler.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Illuminate\Queue\Events\WorkerStopping;
1616
use Illuminate\Routing\Events\RouteMatched;
1717
use Illuminate\Routing\Route;
18+
use Illuminate\Support\Str;
1819
use RuntimeException;
1920
use Sentry\Breadcrumb;
2021
use Sentry\SentrySdk;
@@ -170,14 +171,24 @@ public function __call($method, $arguments)
170171
*/
171172
protected function routerMatchedHandler(Route $route)
172173
{
174+
$routeName = null;
175+
173176
if ($route->getName()) {
174177
// someaction (route name/alias)
175178
$routeName = $route->getName();
176-
} elseif ($route->getActionName()) {
179+
180+
// Laravel 7 route caching generates a route names if the user didn't specify one
181+
// theirselfs to optimize route matching. These route names are useless to the
182+
// developer so if we encounter a generated route name we discard the value
183+
if (Str::startsWith($routeName, 'generated::')) {
184+
$routeName = null;
185+
}
186+
}
187+
188+
if (empty($routeName) && $route->getActionName()) {
177189
// SomeController@someAction (controller action)
178190
$routeName = $route->getActionName();
179-
}
180-
if (empty($routeName) || $routeName === 'Closure') {
191+
} elseif (empty($routeName) || $routeName === 'Closure') {
181192
// /someaction // Fallback to the url
182193
$routeName = $route->uri();
183194
}
@@ -188,6 +199,7 @@ protected function routerMatchedHandler(Route $route)
188199
'route',
189200
$routeName
190201
));
202+
191203
Integration::setTransaction($routeName);
192204
}
193205

0 commit comments

Comments
 (0)