From fc510b4e89d3c0d3301e01f50f8e9667cf141e0c Mon Sep 17 00:00:00 2001 From: Yulianto Dwi Saputro Date: Thu, 29 Sep 2022 21:12:47 +0700 Subject: [PATCH] fix: Status code not populated on transaction if response did not inherit from the Laravel Response class (#573) Co-authored-by: Alex Bouma --- CHANGELOG.md | 2 ++ src/Sentry/Laravel/Tracing/Middleware.php | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8be8b34..381e1ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix status code not 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 diff --git a/src/Sentry/Laravel/Tracing/Middleware.php b/src/Sentry/Laravel/Tracing/Middleware.php index 9045446c..e6b61468 100644 --- a/src/Sentry/Laravel/Tracing/Middleware.php +++ b/src/Sentry/Laravel/Tracing/Middleware.php @@ -4,7 +4,6 @@ use Closure; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Illuminate\Routing\Route; use Sentry\Laravel\Integration; use Sentry\SentrySdk; @@ -12,6 +11,7 @@ use Sentry\Tracing\Span; use Sentry\Tracing\SpanContext; use Sentry\Tracing\TransactionContext; +use Symfony\Component\HttpFoundation\Response; class Middleware { @@ -56,8 +56,8 @@ public function handle($request, Closure $next) /** * Handle the application termination. * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Http\Response $response + * @param \Illuminate\Http\Request $request + * @param \Symfony\Component\HttpFoundation\Response $response * * @return void */ @@ -208,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