All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler Maven / Gradle / Ivy

There is a newer version: 5.0.7
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.otlp.traces;

import org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.marshal.MarshalerUtil;
import org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
import org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.marshal.Serializer;
import org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.otlp.InstrumentationScopeMarshaller;
import org.apache.rocketmq.shaded.io.opentelemetry.exporter.internal.otlp.ResourceMarshaler;
import org.apache.rocketmq.shaded.io.opentelemetry.proto.trace.v1.internal.ResourceSpans;
import org.apache.rocketmq.shaded.io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import org.apache.rocketmq.shaded.io.opentelemetry.sdk.resources.Resource;
import org.apache.rocketmq.shaded.io.opentelemetry.sdk.trace.data.SpanData;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * A Marshaler of ResourceSpans.
 *
 * 

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ public final class ResourceSpansMarshaler extends MarshalerWithSize { private final ResourceMarshaler resourceMarshaler; private final byte[] schemaUrlUtf8; private final InstrumentationScopeSpansMarshaler[] instrumentationScopeSpansMarshalers; /** Returns Marshalers of ResourceSpans created by grouping the provided SpanData. */ public static ResourceSpansMarshaler[] create(Collection spanDataList) { Map>> resourceAndScopeMap = groupByResourceAndScope(spanDataList); ResourceSpansMarshaler[] resourceSpansMarshalers = new ResourceSpansMarshaler[resourceAndScopeMap.size()]; int posResource = 0; for (Map.Entry>> entry : resourceAndScopeMap.entrySet()) { InstrumentationScopeSpansMarshaler[] instrumentationScopeSpansMarshalers = new InstrumentationScopeSpansMarshaler[entry.getValue().size()]; int posInstrumentation = 0; for (Map.Entry> entryIs : entry.getValue().entrySet()) { instrumentationScopeSpansMarshalers[posInstrumentation++] = new InstrumentationScopeSpansMarshaler( InstrumentationScopeMarshaller.create(entryIs.getKey()), MarshalerUtil.toBytes(entryIs.getKey().getSchemaUrl()), entryIs.getValue()); } resourceSpansMarshalers[posResource++] = new ResourceSpansMarshaler( ResourceMarshaler.create(entry.getKey()), MarshalerUtil.toBytes(entry.getKey().getSchemaUrl()), instrumentationScopeSpansMarshalers); } return resourceSpansMarshalers; } ResourceSpansMarshaler( ResourceMarshaler resourceMarshaler, byte[] schemaUrlUtf8, InstrumentationScopeSpansMarshaler[] instrumentationScopeSpansMarshalers) { super(calculateSize(resourceMarshaler, schemaUrlUtf8, instrumentationScopeSpansMarshalers)); this.resourceMarshaler = resourceMarshaler; this.schemaUrlUtf8 = schemaUrlUtf8; this.instrumentationScopeSpansMarshalers = instrumentationScopeSpansMarshalers; } @Override public void writeTo(Serializer output) throws IOException { output.serializeMessage(ResourceSpans.RESOURCE, resourceMarshaler); output.serializeRepeatedMessage(ResourceSpans.SCOPE_SPANS, instrumentationScopeSpansMarshalers); output.serializeString(ResourceSpans.SCHEMA_URL, schemaUrlUtf8); } private static int calculateSize( ResourceMarshaler resourceMarshaler, byte[] schemaUrlUtf8, InstrumentationScopeSpansMarshaler[] instrumentationScopeSpansMarshalers) { int size = 0; size += MarshalerUtil.sizeMessage(ResourceSpans.RESOURCE, resourceMarshaler); size += MarshalerUtil.sizeBytes(ResourceSpans.SCHEMA_URL, schemaUrlUtf8); size += MarshalerUtil.sizeRepeatedMessage( ResourceSpans.SCOPE_SPANS, instrumentationScopeSpansMarshalers); return size; } private static Map>> groupByResourceAndScope(Collection spanDataList) { return MarshalerUtil.groupByResourceAndScope( spanDataList, // TODO(anuraaga): Replace with an internal SdkData type of interface that exposes these // two. SpanData::getResource, SpanData::getInstrumentationScopeInfo, SpanMarshaler::create); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy