Skip to content

Commit

Permalink
Optimized GuzzleHttpClientAspect (#837)
Browse files Browse the repository at this point in the history
* Optimized `GuzzleHttpClientAspect`

* 优化 GuzzleHttpClientAspect 中的响应数据记录逻辑

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Feb 8, 2025
1 parent 186ed1f commit 43bf020
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/Aspect/GuzzleHttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down

0 comments on commit 43bf020

Please sign in to comment.