Skip to content

Commit

Permalink
Measure and log response times of gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
janlanger committed Nov 28, 2017
1 parent 069e154 commit 978af9f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Api/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ private function request(
throw new \InvalidArgumentException('Arguments are missing URL placeholders: ' . json_encode($queries));
}

$requestStartTime = microtime(true);

$response = $this->driver->request(
$method,
$this->apiUrl . '/' . $url,
$data
);

$this->logRequest($method, $endpointName, $originalQueries, $data, $response);
$this->logRequest($method, $endpointName, $originalQueries, $data, $response, microtime(true) - $requestStartTime);

if ($responseValidityCallback !== null) {
$responseValidityCallback($response);
Expand Down Expand Up @@ -281,7 +283,7 @@ public function createResponseByData(array $data, SignatureDataFormatter $respon
$data
);

$this->logRequest(HttpMethod::get(HttpMethod::GET), 'payment/response', [], [], $response);
$this->logRequest(HttpMethod::get(HttpMethod::GET), 'payment/response', [], [], $response, 0.0);

return new Response(
$response->getResponseCode(),
Expand Down Expand Up @@ -337,8 +339,9 @@ private function decodeData(array $responseData, SignatureDataFormatter $signatu
* @param mixed[] $queries
* @param mixed[]|null $requestData
* @param \SlevomatCsobGateway\Api\Response $response
* @param float $responseTime
*/
private function logRequest(HttpMethod $method, string $url, array $queries, ?array $requestData, Response $response): void
private function logRequest(HttpMethod $method, string $url, array $queries, ?array $requestData, Response $response, float $responseTime): void
{
if ($this->logger === null) {
return;
Expand All @@ -365,6 +368,7 @@ private function logRequest(HttpMethod $method, string $url, array $queries, ?ar
'code' => $response->getResponseCode()->getValue(),
'data' => $responseData,
'headers' => $response->getHeaders(),
'time' => $responseTime,
],
];

Expand Down

0 comments on commit 978af9f

Please sign in to comment.