Search in sources :

Example 16 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project wavefront-proxy by wavefrontHQ.

the class OtlpTestHelpers method otlpTraceRequest.

public static ExportTraceServiceRequest otlpTraceRequest(io.opentelemetry.proto.trace.v1.Span otlpSpan) {
    InstrumentationLibrarySpans ilSpans = InstrumentationLibrarySpans.newBuilder().addSpans(otlpSpan).build();
    ResourceSpans rSpans = ResourceSpans.newBuilder().addInstrumentationLibrarySpans(ilSpans).build();
    ExportTraceServiceRequest request = ExportTraceServiceRequest.newBuilder().addResourceSpans(rSpans).build();
    return request;
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans)

Example 17 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project opentelemetry-java-instrumentation by open-telemetry.

the class AgentTestingExporterAccess method getExportedSpans.

@SuppressWarnings("unchecked")
public static List<SpanData> getExportedSpans() {
    List<byte[]> exportRequests;
    try {
        exportRequests = (List<byte[]>) getSpanExportRequests.invokeExact();
    } catch (Throwable t) {
        throw new AssertionError("Could not invoke getSpanExportRequests", t);
    }
    List<ResourceSpans> allResourceSpans = exportRequests.stream().map(serialized -> {
        try {
            return ExportTraceServiceRequest.parseFrom(serialized);
        } catch (InvalidProtocolBufferException e) {
            throw new AssertionError(e);
        }
    }).flatMap(request -> request.getResourceSpansList().stream()).collect(toList());
    List<SpanData> spans = new ArrayList<>();
    for (ResourceSpans resourceSpans : allResourceSpans) {
        Resource resource = resourceSpans.getResource();
        for (InstrumentationLibrarySpans ilSpans : resourceSpans.getInstrumentationLibrarySpansList()) {
            InstrumentationLibrary instrumentationLibrary = ilSpans.getInstrumentationLibrary();
            for (Span span : ilSpans.getSpansList()) {
                String traceId = bytesToHex(span.getTraceId().toByteArray());
                spans.add(TestSpanData.builder().setSpanContext(SpanContext.create(traceId, bytesToHex(span.getSpanId().toByteArray()), TraceFlags.getDefault(), extractTraceState(span.getTraceState()))).setParentSpanContext(SpanContext.create(traceId, bytesToHex(span.getParentSpanId().toByteArray()), TraceFlags.getDefault(), TraceState.getDefault())).setResource(io.opentelemetry.sdk.resources.Resource.create(fromProto(resource.getAttributesList()))).setInstrumentationLibraryInfo(InstrumentationLibraryInfo.create(instrumentationLibrary.getName(), instrumentationLibrary.getVersion())).setName(span.getName()).setStartEpochNanos(span.getStartTimeUnixNano()).setEndEpochNanos(span.getEndTimeUnixNano()).setAttributes(fromProto(span.getAttributesList())).setEvents(span.getEventsList().stream().map(event -> EventData.create(event.getTimeUnixNano(), event.getName(), fromProto(event.getAttributesList()), event.getDroppedAttributesCount() + event.getAttributesCount())).collect(toList())).setStatus(fromProto(span.getStatus())).setKind(fromProto(span.getKind())).setLinks(span.getLinksList().stream().map(link -> LinkData.create(SpanContext.create(bytesToHex(link.getTraceId().toByteArray()), bytesToHex(link.getSpanId().toByteArray()), TraceFlags.getDefault(), extractTraceState(link.getTraceState())), fromProto(link.getAttributesList()), link.getDroppedAttributesCount() + link.getAttributesCount())).collect(toList())).setHasEnded(true).setTotalRecordedEvents(span.getEventsCount() + span.getDroppedEventsCount()).setTotalRecordedLinks(span.getLinksCount() + span.getDroppedLinksCount()).setTotalAttributeCount(span.getAttributesCount() + span.getDroppedAttributesCount()).build());
            }
        }
    }
    return spans;
}
Also used : TraceFlags(io.opentelemetry.api.trace.TraceFlags) LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) KeyValue(io.opentelemetry.proto.common.v1.KeyValue) EventData(io.opentelemetry.sdk.trace.data.EventData) Sum(io.opentelemetry.proto.metrics.v1.Sum) StatusCode(io.opentelemetry.api.trace.StatusCode) ImmutableSummaryPointData(io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryPointData) Attributes(io.opentelemetry.api.common.Attributes) ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Resource(io.opentelemetry.proto.resource.v1.Resource) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) AttributeKey.stringArrayKey(io.opentelemetry.api.common.AttributeKey.stringArrayKey) ExportLogsServiceRequest(io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ValueAtPercentile(io.opentelemetry.sdk.metrics.data.ValueAtPercentile) SpanContext(io.opentelemetry.api.trace.SpanContext) SummaryPointData(io.opentelemetry.sdk.metrics.data.SummaryPointData) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) AttributeKey.doubleArrayKey(io.opentelemetry.api.common.AttributeKey.doubleArrayKey) SpanKind(io.opentelemetry.api.trace.SpanKind) Collectors(java.util.stream.Collectors) ArrayValue(io.opentelemetry.proto.common.v1.ArrayValue) List(java.util.List) InstrumentationLibraryMetrics(io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) AttributeKey.longArrayKey(io.opentelemetry.api.common.AttributeKey.longArrayKey) AnyValue(io.opentelemetry.proto.common.v1.AnyValue) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) Pattern(java.util.regex.Pattern) ImmutableValueAtPercentile(io.opentelemetry.sdk.metrics.internal.data.ImmutableValueAtPercentile) HistogramDataPoint(io.opentelemetry.proto.metrics.v1.HistogramDataPoint) MethodHandle(java.lang.invoke.MethodHandle) StatusData(io.opentelemetry.sdk.trace.data.StatusData) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ImmutableSummaryData(io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryData) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) ArrayList(java.util.ArrayList) TraceState(io.opentelemetry.api.trace.TraceState) Metric(io.opentelemetry.proto.metrics.v1.Metric) DoublePointData(io.opentelemetry.sdk.metrics.data.DoublePointData) HistogramPointData(io.opentelemetry.sdk.metrics.data.HistogramPointData) TraceStateBuilder(io.opentelemetry.api.trace.TraceStateBuilder) LogData(io.opentelemetry.sdk.logs.data.LogData) ImmutableGaugeData(io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData) Severity(io.opentelemetry.sdk.logs.data.Severity) ImmutableSumData(io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) LogRecord(io.opentelemetry.proto.logs.v1.LogRecord) SeverityNumber(io.opentelemetry.proto.logs.v1.SeverityNumber) ExportMetricsServiceRequest(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest) Span(io.opentelemetry.proto.trace.v1.Span) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) NumberDataPoint(io.opentelemetry.proto.metrics.v1.NumberDataPoint) TimeUnit(java.util.concurrent.TimeUnit) ImmutableHistogramPointData(io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData) Collectors.toList(java.util.stream.Collectors.toList) MethodType(java.lang.invoke.MethodType) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) ResourceMetrics(io.opentelemetry.proto.metrics.v1.ResourceMetrics) InstrumentationLibraryLogs(io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs) AttributeKey.booleanArrayKey(io.opentelemetry.api.common.AttributeKey.booleanArrayKey) ImmutableHistogramData(io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData) LinkData(io.opentelemetry.sdk.trace.data.LinkData) SummaryDataPoint(io.opentelemetry.proto.metrics.v1.SummaryDataPoint) Status(io.opentelemetry.proto.trace.v1.Status) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) SpanData(io.opentelemetry.sdk.trace.data.SpanData) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ArrayList(java.util.ArrayList) Resource(io.opentelemetry.proto.resource.v1.Resource) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary)

Example 18 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class EndToEndServiceMapTest method getResourceSpansBatch.

private List<ResourceSpans> getResourceSpansBatch(final String traceId, final List<EndToEndTestSpan> data) {
    final ArrayList<ResourceSpans> spansList = new ArrayList<>();
    for (int i = 0; i < data.size(); i++) {
        final EndToEndTestSpan currData = data.get(i);
        final String parentId = currData.parentId;
        final String spanId = currData.spanId;
        final String serviceName = currData.serviceName;
        final String spanName = currData.name;
        final Span.SpanKind spanKind = currData.spanKind;
        final ResourceSpans rs = getResourceSpans(serviceName, spanName, spanId.getBytes(), parentId != null ? parentId.getBytes() : null, traceId.getBytes(), spanKind);
        spansList.add(rs);
    }
    return spansList;
}
Also used : ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span)

Example 19 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class PeerForwarder method doExecute.

@Override
public List<Record<ExportTraceServiceRequest>> doExecute(final Collection<Record<ExportTraceServiceRequest>> records) {
    final Map<String, List<ResourceSpans>> groupedRS = new HashMap<>();
    // Group ResourceSpans by consistent hashing of traceId
    for (final Record<ExportTraceServiceRequest> record : records) {
        for (final ResourceSpans rs : record.getData().getResourceSpansList()) {
            final List<Map.Entry<String, ResourceSpans>> rsBatch = PeerForwarderUtils.splitByTrace(rs);
            for (final Map.Entry<String, ResourceSpans> entry : rsBatch) {
                final String traceId = entry.getKey();
                final ResourceSpans newRS = entry.getValue();
                final String dataPrepperIp = hashRing.getServerIp(traceId).orElse(StaticPeerListProvider.LOCAL_ENDPOINT);
                groupedRS.computeIfAbsent(dataPrepperIp, x -> new ArrayList<>()).add(newRS);
            }
        }
    }
    final List<Record<ExportTraceServiceRequest>> recordsToProcessLocally = new ArrayList<>();
    final List<CompletableFuture<Record>> forwardedRequestFutures = new ArrayList<>();
    for (final Map.Entry<String, List<ResourceSpans>> entry : groupedRS.entrySet()) {
        final TraceServiceGrpc.TraceServiceBlockingStub client = getClient(entry.getKey());
        // Create ExportTraceRequest for storing single batch of spans
        ExportTraceServiceRequest.Builder currRequestBuilder = ExportTraceServiceRequest.newBuilder();
        int currSpansCount = 0;
        for (final ResourceSpans rs : entry.getValue()) {
            final int rsSize = PeerForwarderUtils.getResourceSpansSize(rs);
            if (currSpansCount >= maxNumSpansPerRequest) {
                final ExportTraceServiceRequest currRequest = currRequestBuilder.build();
                if (isLocalClient(client)) {
                    recordsToProcessLocally.add(new Record<>(currRequest));
                } else {
                    forwardedRequestFutures.add(processRequest(client, currRequest));
                }
                currRequestBuilder = ExportTraceServiceRequest.newBuilder();
                currSpansCount = 0;
            }
            currRequestBuilder.addResourceSpans(rs);
            currSpansCount += rsSize;
        }
        // Dealing with the last batch request
        if (currSpansCount > 0) {
            final ExportTraceServiceRequest currRequest = currRequestBuilder.build();
            if (client == null) {
                recordsToProcessLocally.add(new Record<>(currRequest));
            } else {
                forwardedRequestFutures.add(processRequest(client, currRequest));
            }
        }
    }
    for (final CompletableFuture<Record> future : forwardedRequestFutures) {
        try {
            final Record record = future.get();
            if (record != null) {
                recordsToProcessLocally.add(record);
            }
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Problem with asynchronous peer forwarding", e);
        }
    }
    return recordsToProcessLocally;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) StaticPeerListProvider(com.amazon.dataprepper.plugins.prepper.peerforwarder.discovery.StaticPeerListProvider) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) SocketException(java.net.SocketException) Timer(io.micrometer.core.instrument.Timer) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Map(java.util.Map) AbstractPrepper(com.amazon.dataprepper.model.prepper.AbstractPrepper) Record(com.amazon.dataprepper.model.record.Record) ExecutorService(java.util.concurrent.ExecutorService) Counter(io.micrometer.core.instrument.Counter) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Logger(org.slf4j.Logger) Prepper(com.amazon.dataprepper.model.prepper.Prepper) Collection(java.util.Collection) NetworkInterface(java.net.NetworkInterface) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TraceServiceGrpc(io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc) UnknownHostException(java.net.UnknownHostException) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) DataPrepperPlugin(com.amazon.dataprepper.model.annotations.DataPrepperPlugin) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.amazon.dataprepper.model.record.Record) ExecutionException(java.util.concurrent.ExecutionException) TraceServiceGrpc(io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 20 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class PeerForwarderUtils method splitByTrace.

public static List<Map.Entry<String, ResourceSpans>> splitByTrace(final ResourceSpans rs) {
    final List<Map.Entry<String, ResourceSpans>> result = new ArrayList<>();
    for (final InstrumentationLibrarySpans ils : rs.getInstrumentationLibrarySpansList()) {
        final Map<String, ResourceSpans.Builder> batches = new HashMap<>();
        for (final Span span : ils.getSpansList()) {
            final String sTraceId = Hex.toHexString(span.getTraceId().toByteArray());
            if (!batches.containsKey(sTraceId)) {
                final ResourceSpans.Builder newRSBuilder = ResourceSpans.newBuilder().setResource(rs.getResource());
                newRSBuilder.addInstrumentationLibrarySpansBuilder().setInstrumentationLibrary(ils.getInstrumentationLibrary());
                batches.put(sTraceId, newRSBuilder);
            }
            // there is only one instrumentation library per batch
            batches.get(sTraceId).getInstrumentationLibrarySpansBuilder(0).addSpans(span);
        }
        batches.forEach((traceId, rsBuilder) -> result.add(new AbstractMap.SimpleEntry<>(traceId, rsBuilder.build())));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ArrayList(java.util.ArrayList) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span)

Aggregations

ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)22 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)13 InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)11 Span (io.opentelemetry.proto.trace.v1.Span)10 ByteString (com.google.protobuf.ByteString)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Record (com.amazon.dataprepper.model.record.Record)8 Measurement (io.micrometer.core.instrument.Measurement)5 StringJoiner (java.util.StringJoiner)5 InstrumentationLibrary (io.opentelemetry.proto.common.v1.InstrumentationLibrary)4 HashMap (java.util.HashMap)4 List (java.util.List)4 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 Channel (io.grpc.Channel)3 SpanContext (io.opentelemetry.api.trace.SpanContext)3 TraceServiceGrpc (io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc)3 Resource (io.opentelemetry.proto.resource.v1.Resource)3 Map (java.util.Map)3