diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 37376b27..7879f79b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -160,6 +160,11 @@ parameters: count: 1 path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php + - + message: "#^Class Laravel\\\\Lumen\\\\Application not found\\.$#" + count: 1 + path: src/Sentry/Laravel/Tracing/Middleware.php + - message: "#^Class Laravel\\\\Lumen\\\\Application not found\\.$#" count: 2 diff --git a/src/Sentry/Laravel/Tracing/Middleware.php b/src/Sentry/Laravel/Tracing/Middleware.php index 3d4e5b42..89eb0a6c 100644 --- a/src/Sentry/Laravel/Tracing/Middleware.php +++ b/src/Sentry/Laravel/Tracing/Middleware.php @@ -112,8 +112,7 @@ public function terminate(Request $request, $response): void return; } - // We stop here if a route has not been matched unless we are configured to trace missing routes - if (!$this->didRouteMatch && config('sentry.tracing.missing_routes', false) === false) { + if ($this->shouldRouteBeIgnored($request)) { return; } @@ -279,6 +278,21 @@ private function internalSignalRouteWasMatched(): void $this->didRouteMatch = true; } + /** + * Indicates if the route should be ignored and the transaction discarded. + */ + private function shouldRouteBeIgnored(Request $request): bool + { + // Laravel Lumen doesn't use `illuminate/routing`. + // Instead we use the route available on the request to detect if a route was matched. + if ($this->app instanceof LumenApplication) { + return $request->route() === null && config('sentry.tracing.missing_routes', false) === false; + } + + // If a route has not been matched we ignore unless we are configured to trace missing routes + return !$this->didRouteMatch && config('sentry.tracing.missing_routes', false) === false; + } + public static function signalRouteWasMatched(): void { if (!app()->bound(self::class)) {