function SpanConverter::convert
File
-
vendor/
open-telemetry/ exporter-otlp/ SpanConverter.php, line 38
Class
Namespace
OpenTelemetry\Contrib\OtlpCode
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;
}