Skip to content

Commit

Permalink
AUT-2275: do not log for every request
Browse files Browse the repository at this point in the history
Co-authored-by: kapa <richard.nagy@emarsys.com>
Co-authored-by: tsch <peter.kozma@emarsys.com>
  • Loading branch information
3 people committed Oct 2, 2023
1 parent 84786ea commit 7301e44
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions src/Suite/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ private function sendRequestWithBody(string $url, $data, $method)
private function executeRequest(RequestInterface $request = null)
{
try {
$this->logRequest($request, 'executing');
$response = $this->client->send($request, [
'on_stats' => function (TransferStats $stats) use ($request) {
$this->logRequest($request, 'stats', $stats);
}
]);
$this->logRequest($request, 'successful');
$response = $this->client->send($request);
return $this->responseProcessor->processResponse($request, $response);
} catch (BadResponseException $ex) {
$this->logger->error($ex->getMessage(), ['error' => $ex]);
Expand Down Expand Up @@ -180,27 +174,4 @@ private function buildUrlWithParameters(string $url, array $data): string
return $url;
}
}

private function logRequest(RequestInterface $request, string $event, TransferStats $stats = null)
{
$context = [
'application' => [
'origin' => [
'kind' => 'php_suite_api_client',
'category' => 'request',
'type' => $event
]],
'http' => ['request' => ['method'=>$request->getMethod()]],
'url' => ['full' => $request->getUri()],
];

$context['application'] += $stats ? [
'metric' => [
'name' => 'http_request_time_ms',
'value' => ['integer'=> (int)($stats->getTransferTime() * 1000)]
]
] : [];

$this->logger->info("request $event", $context);
}
}

0 comments on commit 7301e44

Please sign in to comment.