From 50087743bdae2f1d6f6193f104241a7713d89147 Mon Sep 17 00:00:00 2001 From: Yulianto Dwi Saputro Date: Thu, 29 Sep 2022 20:44:36 +0700 Subject: [PATCH 1/4] Fix tracing not finished if using JsonResponse Fixing terminate method if return is JsonResponse instance --- src/Sentry/Laravel/Tracing/Middleware.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Sentry/Laravel/Tracing/Middleware.php b/src/Sentry/Laravel/Tracing/Middleware.php index 9045446c..babb66d5 100644 --- a/src/Sentry/Laravel/Tracing/Middleware.php +++ b/src/Sentry/Laravel/Tracing/Middleware.php @@ -5,6 +5,7 @@ use Closure; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Http\JsonResponse; use Illuminate\Routing\Route; use Sentry\Laravel\Integration; use Sentry\SentrySdk; @@ -57,7 +58,7 @@ public function handle($request, Closure $next) * Handle the application termination. * * @param \Illuminate\Http\Request $request - * @param \Illuminate\Http\Response $response + * @param \Illuminate\Http\Response|\Illuminate\Http\JsonResponse $response * * @return void */ @@ -76,7 +77,7 @@ public function terminate($request, $response): void $this->hydrateRequestData($request); } - if ($response instanceof Response) { + if ($response instanceof Response || $response instanceof JsonResponse) { $this->hydrateResponseData($response); } From 50750eeb85ff44c9bb6209a07ad185586c6fc38e Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 29 Sep 2022 15:59:06 +0200 Subject: [PATCH 2/4] Use the base Response class instead of the more specific Laravel Response class --- src/Sentry/Laravel/Tracing/Middleware.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Sentry/Laravel/Tracing/Middleware.php b/src/Sentry/Laravel/Tracing/Middleware.php index babb66d5..e6b61468 100644 --- a/src/Sentry/Laravel/Tracing/Middleware.php +++ b/src/Sentry/Laravel/Tracing/Middleware.php @@ -4,8 +4,6 @@ use Closure; use Illuminate\Http\Request; -use Illuminate\Http\Response; -use Illuminate\Http\JsonResponse; use Illuminate\Routing\Route; use Sentry\Laravel\Integration; use Sentry\SentrySdk; @@ -13,6 +11,7 @@ use Sentry\Tracing\Span; use Sentry\Tracing\SpanContext; use Sentry\Tracing\TransactionContext; +use Symfony\Component\HttpFoundation\Response; class Middleware { @@ -57,8 +56,8 @@ public function handle($request, Closure $next) /** * Handle the application termination. * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Http\Response|\Illuminate\Http\JsonResponse $response + * @param \Illuminate\Http\Request $request + * @param \Symfony\Component\HttpFoundation\Response $response * * @return void */ @@ -77,7 +76,7 @@ public function terminate($request, $response): void $this->hydrateRequestData($request); } - if ($response instanceof Response || $response instanceof JsonResponse) { + if ($response instanceof Response) { $this->hydrateResponseData($response); } @@ -209,7 +208,7 @@ private function hydrateRequestData(Request $request): void private function hydrateResponseData(Response $response): void { - $this->transaction->setHttpStatus($response->status()); + $this->transaction->setHttpStatus($response->getStatusCode()); } private function updateTransactionNameIfDefault(?string $name): void From 92168f008fb5eaed31297789c8c830d6541d0bf2 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 29 Sep 2022 16:01:05 +0200 Subject: [PATCH 3/4] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8be8b34..1883341d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix status code not always populated on transaction if response did not inherit from `Illuminate\Http\Response` like `Illuminate\Http\JsonResponse` (#573) + ## 2.13.0 - Only catch `BindingResolutionException` when trying to get the PSR-7 request object from the container From dd68b6cb86eec59874a7ee8262e4705445797409 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 29 Sep 2022 16:03:35 +0200 Subject: [PATCH 4/4] Fix changelog wording --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1883341d..381e1ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- Fix status code not always populated on transaction if response did not inherit from `Illuminate\Http\Response` like `Illuminate\Http\JsonResponse` (#573) +- Fix status code not populated on transaction if response did not inherit from `Illuminate\Http\Response` like `Illuminate\Http\JsonResponse` (#573) ## 2.13.0