From 23c14c3025904798dd4318fd4659616de46dbcbc Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 2 Nov 2020 11:53:21 +0100 Subject: [PATCH] Fix stripping the base namespace for route name (#406) --- CHANGELOG.md | 2 ++ src/Sentry/Laravel/Integration.php | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce5e170c..c37ae1bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix incorrectly stripped base controller action from transaction name (#406) + ## 2.1.1 - Fix for potential `Undefined index: controllers_base_namespace.` notice diff --git a/src/Sentry/Laravel/Integration.php b/src/Sentry/Laravel/Integration.php index ae767e0b..0f6f1661 100644 --- a/src/Sentry/Laravel/Integration.php +++ b/src/Sentry/Laravel/Integration.php @@ -149,7 +149,14 @@ public static function extractNameForRoute(Route $route): ?string if (empty($routeName) && $route->getActionName()) { // SomeController@someAction (controller action) - $routeName = ltrim($route->getActionName(), (self::$baseControllerNamespace ?? '') . '\\'); + $routeName = $route->getActionName(); + + $baseNamespace = self::$baseControllerNamespace ?? ''; + + // Strip away the base namespace from the action name + if (!empty($baseNamespace)) { + $routeName = Str::after($routeName, $baseNamespace . '\\'); + } } if (empty($routeName) || $routeName === 'Closure') {