Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LogsConverter.php

function LogsConverter::convert

@psalm-suppress InvalidArgument

Parameters

iterable<ReadableLogRecord> $logs:

File

vendor/open-telemetry/exporter-otlp/LogsConverter.php, line 32

Class

LogsConverter

Namespace

OpenTelemetry\Contrib\Otlp

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal