class LogsExporter
@psalm-import-type SUPPORTED_CONTENT_TYPES from ProtobufSerializer
Hierarchy
- class \OpenTelemetry\Contrib\Otlp\LogsExporter implements \OpenTelemetry\SDK\Logs\LogRecordExporterInterface uses \OpenTelemetry\API\Behavior\LogsMessagesTrait
Expanded class hierarchy of LogsExporter
File
-
vendor/
open-telemetry/ exporter-otlp/ LogsExporter.php, line 20
Namespace
OpenTelemetry\Contrib\OtlpView source
class LogsExporter implements LogRecordExporterInterface {
use LogsMessagesTrait;
private ProtobufSerializer $serializer;
/**
* @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport
*/
public function __construct(TransportInterface $transport) {
if (!class_exists('\\Google\\Protobuf\\Api')) {
throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
}
$this->serializer = ProtobufSerializer::forTransport($this->transport);
}
/**
* @param iterable<ReadableLogRecord> $batch
*/
public function export(iterable $batch, ?CancellationInterface $cancellation = null) : FutureInterface {
return $this->transport
->send($this->serializer
->serialize((new LogsConverter($this->serializer))
->convert($batch)), $cancellation)
->map(function (?string $payload) : bool {
if ($payload === null) {
return true;
}
$serviceResponse = new ExportLogsServiceResponse();
$this->serializer
->hydrate($serviceResponse, $payload);
$partialSuccess = $serviceResponse->getPartialSuccess();
if ($partialSuccess !== null && $partialSuccess->getRejectedLogRecords()) {
self::logError('Export partial success', [
'rejected_logs' => $partialSuccess->getRejectedLogRecords(),
'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;
});
}
public function forceFlush(?CancellationInterface $cancellation = null) : bool {
return $this->transport
->forceFlush($cancellation);
}
public function shutdown(?CancellationInterface $cancellation = null) : bool {
return $this->transport
->shutdown($cancellation);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
LogsExporter::$serializer | private | property | ||
LogsExporter::export | public | function | Overrides LogRecordExporterInterface::export | |
LogsExporter::forceFlush | public | function | Overrides LogRecordExporterInterface::forceFlush | |
LogsExporter::shutdown | public | function | Overrides LogRecordExporterInterface::shutdown | |
LogsExporter::__construct | public | function | @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport | |
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 |