Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Lumen performance traces not collected because route never matched #822

Merged
merged 3 commits into from
Jan 16, 2024
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
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/Sentry/Laravel/Tracing/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down