function LogsConverter::convert
@psalm-suppress InvalidArgument
Parameters
iterable<ReadableLogRecord> $logs:
File
-
vendor/
open-telemetry/ exporter-otlp/ LogsConverter.php, line 32
Class
Namespace
OpenTelemetry\Contrib\OtlpCode
public function convert(iterable $logs) : ExportLogsServiceRequest {
$pExportLogsServiceRequest = new ExportLogsServiceRequest();
$scopeLogs = [];
$resourceLogs = [];
$resourceCache = [];
$scopeCache = [];
foreach ($logs as $log) {
$resource = $log->getResource();
$instrumentationScope = $log->getInstrumentationScope();
$resourceId = $resourceCache[spl_object_id($resource)] ??= serialize([
$resource->getSchemaUrl(),
$resource->getAttributes()
->toArray(),
$resource->getAttributes()
->getDroppedAttributesCount(),
]);
$instrumentationScopeId = $scopeCache[spl_object_id($instrumentationScope)] ??= serialize([
$instrumentationScope->getName(),
$instrumentationScope->getVersion(),
$instrumentationScope->getSchemaUrl(),
$instrumentationScope->getAttributes()
->toArray(),
$instrumentationScope->getAttributes()
->getDroppedAttributesCount(),
]);
if (($pResourceLogs = $resourceLogs[$resourceId] ?? null) === null) {
/** @psalm-suppress InvalidArgument */
$pExportLogsServiceRequest->getResourceLogs()[] = $resourceLogs[$resourceId] = $pResourceLogs = $this->convertResourceLogs($resource);
}
if (($pScopeLogs = $scopeLogs[$resourceId][$instrumentationScopeId] ?? null) === null) {
$pResourceLogs->getScopeLogs()[] = $scopeLogs[$resourceId][$instrumentationScopeId] = $pScopeLogs = $this->convertInstrumentationScope($instrumentationScope);
}
$pScopeLogs->getLogRecords()[] = $this->convertLogRecord($log);
}
return $pExportLogsServiceRequest;
}