class MetricExporter
@psalm-import-type SUPPORTED_CONTENT_TYPES from ProtobufSerializer
Hierarchy
- class \OpenTelemetry\Contrib\Otlp\MetricExporter implements \OpenTelemetry\SDK\Metrics\PushMetricExporterInterface, \OpenTelemetry\SDK\Metrics\AggregationTemporalitySelectorInterface uses \OpenTelemetry\API\Behavior\LogsMessagesTrait
Expanded class hierarchy of MetricExporter
See also
https://github.com/open-telemetry/opentelemetry-specification/blob/main…
https://github.com/open-telemetry/opentelemetry-specification/blob/main…
File
-
vendor/
open-telemetry/ exporter-otlp/ MetricExporter.php, line 22
Namespace
OpenTelemetry\Contrib\OtlpView source
final class MetricExporter implements PushMetricExporterInterface, AggregationTemporalitySelectorInterface {
use LogsMessagesTrait;
private ProtobufSerializer $serializer;
/**
* @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport
*/
public function __construct(TransportInterface $transport, string|Temporality|null $temporality = null) {
if (!class_exists('\\Google\\Protobuf\\Api')) {
throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
}
$this->serializer = ProtobufSerializer::forTransport($this->transport);
}
public function temporality(MetricMetadataInterface $metric) : Temporality|string|null {
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();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
LogsMessagesTrait::doLog | private static | function | ||
LogsMessagesTrait::logDebug | protected static | function | ||
LogsMessagesTrait::logError | protected static | function | ||
LogsMessagesTrait::logInfo | protected static | function | ||
LogsMessagesTrait::logNotice | protected static | function | ||
LogsMessagesTrait::logWarning | protected static | function | ||
LogsMessagesTrait::shouldLog | private static | function | ||
MetricExporter::$serializer | private | property | ||
MetricExporter::export | public | function | ||
MetricExporter::forceFlush | public | function | Overrides PushMetricExporterInterface::forceFlush | |
MetricExporter::shutdown | public | function | ||
MetricExporter::temporality | public | function | Returns the temporality to use for the given metric. | Overrides AggregationTemporalitySelectorInterface::temporality |
MetricExporter::__construct | public | function | @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport |