in src/Transport.php [317:385]
public function sendRequest(RequestInterface $request): ResponseInterface
{
if (empty($request->getUri()->getHost())) {
$node = $this->nodePool->nextNode();
$request = $this->setupConnectionUri($node, $request);
}
$request = $this->decorateRequest($request);
$this->lastRequest = $request;
$this->logRequest("Request", $request);
// OpenTelemetry get tracer
if (getenv(OpenTelemetry::ENV_VARIABLE_ENABLED)) {
$tracer = $this->getOTelTracer();
}
$lastNetworkException = null;
$count = -1;
while ($count < $this->getRetries()) {
try {
$count++;
// OpenTelemetry span start
if (!empty($tracer)) {
if ($request instanceof ServerRequestInterface) {
$opts = $request->getAttribute(OpenTelemetry::PSR7_OTEL_ATTRIBUTE_NAME, []);
}
$spanName = $opts['db.operation.name'] ?? $request->getUri()->getPath();
$span = $tracer->spanBuilder($spanName)->startSpan();
$span->setAttribute('http.request.method', $request->getMethod());
$span->setAttribute('url.full', $this->getFullUrl($request));
$span->setAttribute('server.address', $request->getUri()->getHost());
$span->setAttribute('server.port', $request->getUri()->getPort());
if (!empty($opts)) {
$span->setAttributes($opts);
}
}
$response = $this->client->sendRequest($request);
$this->lastResponse = $response;
$this->logResponse("Response", $response, $count);
return $response;
} catch (NetworkExceptionInterface $e) {
$lastNetworkException = $e;
$this->logger->error(sprintf("Retry %d: %s", $count, $e->getMessage()));
if (!empty($span)) {
$span->setAttribute('error.type', $e->getMessage());
}
if (isset($node)) {
$node->markAlive(false);
$node = $this->nodePool->nextNode();
$request = $this->setupConnectionUri($node, $request);
}
} catch (ClientExceptionInterface $e) {
$this->logger->error(sprintf("Retry %d: %s", $count, $e->getMessage()));
if (!empty($span)) {
$span->setAttribute('error.type', $e->getMessage());
}
throw $e;
} finally {
// OpenTelemetry span end
if (!empty($span)) {
$span->end();
}
}
}
$exceededMsg = sprintf("Exceeded maximum number of retries (%d)", $this->getRetries());
$this->logger->error($exceededMsg);
throw new NoNodeAvailableException($exceededMsg, 0, $lastNetworkException);
}