$transport */ public function __construct(TransportInterface $transport, $temporality = null) { if (!class_exists('\Google\Protobuf\Api')) { throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)'); } $this->transport = $transport; $this->serializer = ProtobufSerializer::forTransport($transport); $this->temporality = $temporality; } public function temporality(MetricMetadataInterface $metric) { return $this->temporality ?? $metric->temporality(); } public function export(iterable $batch): bool { return $this->transport ->send($this->serializer->serialize((new MetricConverter($this->serializer))->convert($batch))) ->map(function (?string $payload): bool { if ($payload === null) { return true; } $serviceResponse = new ExportMetricsServiceResponse(); $this->serializer->hydrate($serviceResponse, $payload); $partialSuccess = $serviceResponse->getPartialSuccess(); if ($partialSuccess !== null && $partialSuccess->getRejectedDataPoints()) { self::logError('Export partial success', [ 'rejected_data_points' => $partialSuccess->getRejectedDataPoints(), 'error_message' => $partialSuccess->getErrorMessage(), ]); return false; } if ($partialSuccess !== null && $partialSuccess->getErrorMessage()) { self::logWarning('Export success with warnings/suggestions', ['error_message' => $partialSuccess->getErrorMessage()]); } return true; }) ->catch(static function (Throwable $throwable): bool { self::logError('Export failure', ['exception' => $throwable]); return false; }) ->await(); } public function shutdown(): bool { return $this->transport->shutdown(); } public function forceFlush(): bool { return $this->transport->forceFlush(); } }