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

Breadcrumb

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

function MetricConverter::convert

Parameters

iterable<SDK\Metrics\Data\Metric> $batch:

File

vendor/open-telemetry/exporter-otlp/MetricConverter.php, line 40

Class

MetricConverter

Namespace

OpenTelemetry\Contrib\Otlp

Code

public function convert(iterable $batch) : ExportMetricsServiceRequest {
    $pExportMetricsServiceRequest = new ExportMetricsServiceRequest();
    $resourceMetrics = [];
    $resourceCache = [];
    $scopeMetrics = [];
    $scopeCache = [];
    foreach ($batch as $metric) {
        $resource = $metric->resource;
        $instrumentationScope = $metric->instrumentationScope;
        $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 (($pResourceMetrics = $resourceMetrics[$resourceId] ?? null) === null) {
            
            /** @psalm-suppress InvalidArgument */
            $pExportMetricsServiceRequest->getResourceMetrics()[] = $resourceMetrics[$resourceId] = $pResourceMetrics = $this->convertResourceMetrics($resource);
        }
        if (($pScopeMetrics = $scopeMetrics[$resourceId][$instrumentationScopeId] ?? null) === null) {
            
            /** @psalm-suppress InvalidArgument */
            $pResourceMetrics->getScopeMetrics()[] = $scopeMetrics[$resourceId][$instrumentationScopeId] = $pScopeMetrics = $this->convertScopeMetrics($instrumentationScope);
        }
        
        /** @psalm-suppress InvalidArgument */
        $pScopeMetrics->getMetrics()[] = $this->convertMetric($metric);
    }
    return $pExportMetricsServiceRequest;
}

API Navigation

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