Skip to content

Commit

Permalink
Add connect exceptions on HTTP client metrics (#9)
Browse files Browse the repository at this point in the history
* feat identified connect exception on http promise rejection

* use interface instead exception

* abstract catch of exception

* add specific message on errors
lukkas-lukkas authored Jan 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 6c2980c commit c92e9fe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Aspect/HttpClientMetricAspect.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Uri;
@@ -49,6 +50,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
'host' => $host,
'method' => $method,
'http_status_code' => '200',
'message' => 'success',
];

$timer = new Timer('http_client_requests', $labels);
@@ -74,8 +76,15 @@ private function onFullFilled(Timer $timer, array $labels): callable

private function onRejected(Timer $timer, array $labels): callable
{
return function (RequestException $exception) use ($timer, $labels) {
$labels['http_status_code'] = (string) $exception->getResponse()->getStatusCode();
return function (TransferException $exception) use ($timer, $labels) {
$labels['http_status_code'] = '';
$labels['message'] = 'connect_error';

if ($exception instanceof RequestException) {
$labels['http_status_code'] = (string) $exception->getResponse()->getStatusCode();
$labels['message'] = 'request_error';
}

$timer->end($labels);

return Create::rejectionFor($exception);

0 comments on commit c92e9fe

Please sign in to comment.