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

Breadcrumb

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

function SpanConverter::convert

File

vendor/open-telemetry/exporter-otlp/SpanConverter.php, line 38

Class

SpanConverter

Namespace

OpenTelemetry\Contrib\Otlp

Code

public function convert(iterable $spans) : ExportTraceServiceRequest {
    $pExportTraceServiceRequest = new ExportTraceServiceRequest();
    $resourceSpans = [];
    $resourceCache = [];
    $scopeSpans = [];
    $scopeCache = [];
    foreach ($spans as $span) {
        $resource = $span->getResource();
        $instrumentationScope = $span->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 (($pResourceSpans = $resourceSpans[$resourceId] ?? null) === null) {
            
            /** @psalm-suppress InvalidArgument */
            $pExportTraceServiceRequest->getResourceSpans()[] = $resourceSpans[$resourceId] = $pResourceSpans = $this->convertResourceSpans($resource);
        }
        if (($pScopeSpans = $scopeSpans[$resourceId][$instrumentationScopeId] ?? null) === null) {
            
            /** @psalm-suppress InvalidArgument */
            $pResourceSpans->getScopeSpans()[] = $scopeSpans[$resourceId][$instrumentationScopeId] = $pScopeSpans = $this->convertScopeSpans($instrumentationScope);
        }
        
        /** @psalm-suppress InvalidArgument */
        $pScopeSpans->getSpans()[] = $this->convertSpan($span);
    }
    return $pExportTraceServiceRequest;
}

API Navigation

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