diff --git a/src/telescope/src/Aspect/GuzzleHttpClientAspect.php b/src/telescope/src/Aspect/GuzzleHttpClientAspect.php index fcf7a5908..127b85619 100644 --- a/src/telescope/src/Aspect/GuzzleHttpClientAspect.php +++ b/src/telescope/src/Aspect/GuzzleHttpClientAspect.php @@ -64,23 +64,22 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) try { $request = $stats->getRequest(); $response = $stats->getResponse(); - $data = [ - 'status' => $response->getStatusCode(), - 'reason' => $response->getReasonPhrase(), - 'headers' => $response->getHeaders(), - 'body' => $this->getResponsePayload($response), - ]; - - Telescope::recordClientRequest(IncomingEntry::make([ + $content = [ 'method' => $request->getMethod(), 'uri' => $request->getUri()->__toString(), 'headers' => $request->getHeaders(), - 'response_status' => $data['status'], - 'response_headers' => $data['headers'], - 'response_data' => $data, 'duration' => $stats->getTransferTime() * 1000, - ])); - } catch (Throwable $e) { + ]; + + if ($response = $stats->getResponse()) { + $content['response_status'] = $response->getStatusCode(); + $content['response_headers'] = $response->getHeaders(); + $content['response_reason'] = $response->getReasonPhrase(); + $content['response_payload'] = $this->getResponsePayload($response); + } + + Telescope::recordClientRequest(IncomingEntry::make($content)); + } catch (Throwable $exception) { // We will catch the exception to prevent the request from being interrupted. }