Skip to content

Commit

Permalink
Laravel Lumen performance traces not collected because route never ma…
Browse files Browse the repository at this point in the history
…tched (#822)

* fix: lumen `tracing` cannot be reported.

* ignore phpstan error

* CR

---------

Co-authored-by: Alex Bouma <alex@bouma.me>
  • Loading branch information
summerKK and stayallive authored Jan 16, 2024
1 parent 9421a96 commit 129c0b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit 129c0b3

Please sign in to comment.