Search in sources :

Example 1 with RawSpanBuilder

use of com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpanBuilder in project data-prepper by opensearch-project.

the class OTelTraceRawPrepper method doExecute.

/**
 * execute the prepper logic which could potentially modify the incoming record. The level to which the record has
 * been modified depends on the implementation
 *
 * @param records Input records that will be modified/processed
 * @return Record  modified output records
 */
@Override
public Collection<Record<String>> doExecute(Collection<Record<ExportTraceServiceRequest>> records) {
    final List<RawSpan> rawSpans = new LinkedList<>();
    for (Record<ExportTraceServiceRequest> ets : records) {
        for (ResourceSpans rs : ets.getData().getResourceSpansList()) {
            try {
                final String serviceName = OTelProtoHelper.getServiceName(rs.getResource()).orElse(null);
                final Map<String, Object> resourceAttributes = OTelProtoHelper.getResourceAttributes(rs.getResource());
                for (InstrumentationLibrarySpans is : rs.getInstrumentationLibrarySpansList()) {
                    for (Span sp : is.getSpansList()) {
                        final RawSpan rawSpan = new RawSpanBuilder().setFromSpan(sp, is.getInstrumentationLibrary(), serviceName, resourceAttributes).build();
                        processRawSpan(rawSpan, rawSpans);
                    }
                }
            } catch (Exception ex) {
                LOG.error("Unable to process invalid ResourceSpan {} :", rs, ex);
                resourceSpanErrorsCounter.increment();
                totalProcessingErrorsCounter.increment();
            }
        }
    }
    rawSpans.addAll(getTracesToFlushByGarbageCollection());
    return convertRawSpansToJsonRecords(rawSpans);
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) RawSpan(com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpan) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) RawSpan(com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpan) Span(io.opentelemetry.proto.trace.v1.Span) LinkedList(java.util.LinkedList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) RawSpanBuilder(com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpanBuilder)

Aggregations

RawSpan (com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpan)1 RawSpanBuilder (com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpanBuilder)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)1 InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)1 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)1 Span (io.opentelemetry.proto.trace.v1.Span)1 LinkedList (java.util.LinkedList)1