Search in sources :

Example 1 with InstrumentationLibrarySpans

use of io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans in project inspectit-ocelot by inspectIT.

the class OpenTelemetryProtoConverter method toSpanData.

/**
 * @return Converts an {@link InstrumentationLibrarySpans} instance to a stream of individual {@link SpanData} instances.
 */
private Stream<SpanData> toSpanData(InstrumentationLibrarySpans librarySpans, Resource resource, Map<String, String> customSpanAttributes) {
    InstrumentationLibrary library = librarySpans.getInstrumentationLibrary();
    InstrumentationLibraryInfo libraryInfo = InstrumentationLibraryInfo.create(library.getName(), library.getVersion());
    return librarySpans.getSpansList().stream().map(protoSpan -> OcelotSpanUtils.createSpanData(protoSpan, resource, libraryInfo, customSpanAttributes)).filter(Objects::nonNull);
}
Also used : java.util(java.util) RequestUtils(rocks.inspectit.oce.eum.server.utils.RequestUtils) ImmutableMap(com.google.common.collect.ImmutableMap) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) EumServerConfiguration(rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) HttpServletRequest(javax.servlet.http.HttpServletRequest) Stream(java.util.stream.Stream) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) OcelotSpanUtils(io.opentelemetry.sdk.trace.OcelotSpanUtils) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary)

Example 2 with InstrumentationLibrarySpans

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

the class OtlpProtobufUtils method fromOtlpRequest.

// TODO: consider transforming a single span and returning it for immedidate reporting in
// wfSender. This could be more efficient, and also more reliable in the event the loops
// below throw an error and we don't report any of the list.
@VisibleForTesting
static List<WavefrontSpanAndLogs> fromOtlpRequest(ExportTraceServiceRequest request, @Nullable ReportableEntityPreprocessor preprocessor, String defaultSource) {
    List<WavefrontSpanAndLogs> wfSpansAndLogs = new ArrayList<>();
    for (ResourceSpans rSpans : request.getResourceSpansList()) {
        Resource resource = rSpans.getResource();
        OTLP_DATA_LOGGER.finest(() -> "Inbound OTLP Resource: " + resource);
        for (InstrumentationLibrarySpans ilSpans : rSpans.getInstrumentationLibrarySpansList()) {
            InstrumentationLibrary iLibrary = ilSpans.getInstrumentationLibrary();
            OTLP_DATA_LOGGER.finest(() -> "Inbound OTLP Instrumentation Library: " + iLibrary);
            for (io.opentelemetry.proto.trace.v1.Span otlpSpan : ilSpans.getSpansList()) {
                OTLP_DATA_LOGGER.finest(() -> "Inbound OTLP Span: " + otlpSpan);
                wfSpansAndLogs.add(transformAll(otlpSpan, resource.getAttributesList(), iLibrary, preprocessor, defaultSource));
            }
        }
    }
    return wfSpansAndLogs;
}
Also used : InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ArrayList(java.util.ArrayList) Resource(io.opentelemetry.proto.resource.v1.Resource) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with InstrumentationLibrarySpans

use of io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans 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)

Example 4 with InstrumentationLibrarySpans

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

the class TraceRequestMarshalerTest method toProtoResourceSpans.

@Test
void toProtoResourceSpans() {
    ResourceSpansMarshaler[] resourceSpansMarshalers = ResourceSpansMarshaler.create(Collections.singleton(TestSpanData.builder().setHasEnded(true).setSpanContext(SPAN_CONTEXT).setParentSpanContext(SpanContext.getInvalid()).setName("GET /api/endpoint").setKind(SpanKind.SERVER).setStartEpochNanos(12345).setEndEpochNanos(12349).setStatus(StatusData.unset()).setInstrumentationLibraryInfo(InstrumentationLibraryInfo.create("testLib", "1.0", "http://url")).setResource(Resource.builder().put("one", 1).setSchemaUrl("http://url").build()).build()));
    assertThat(resourceSpansMarshalers).hasSize(1);
    ResourceSpans onlyResourceSpans = parse(ResourceSpans.getDefaultInstance(), resourceSpansMarshalers[0]);
    assertThat(onlyResourceSpans.getSchemaUrl()).isEqualTo("http://url");
    assertThat(onlyResourceSpans.getInstrumentationLibrarySpansCount()).isEqualTo(1);
    InstrumentationLibrarySpans instrumentationLibrarySpans = onlyResourceSpans.getInstrumentationLibrarySpans(0);
    assertThat(instrumentationLibrarySpans.getSchemaUrl()).isEqualTo("http://url");
    assertThat(instrumentationLibrarySpans.getInstrumentationLibrary()).isEqualTo(InstrumentationLibrary.newBuilder().setName("testLib").setVersion("1.0").build());
}
Also used : InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Test(org.junit.jupiter.api.Test)

Example 5 with InstrumentationLibrarySpans

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

the class OtlpExporterIntegrationTest method testTraceExport.

private static void testTraceExport(SpanExporter spanExporter) {
    SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).setResource(RESOURCE).build();
    SpanContext linkContext = SpanContext.create(IdGenerator.random().generateTraceId(), IdGenerator.random().generateSpanId(), TraceFlags.getDefault(), TraceState.getDefault());
    Span span = tracerProvider.get(OtlpExporterIntegrationTest.class.getName()).spanBuilder("my span name").addLink(linkContext).startSpan();
    span.setAttribute("key", "value");
    span.addEvent("event");
    span.end();
    await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> assertThat(grpcServer.traceRequests).hasSize(1));
    ExportTraceServiceRequest request = grpcServer.traceRequests.get(0);
    assertThat(request.getResourceSpansCount()).isEqualTo(1);
    ResourceSpans resourceSpans = request.getResourceSpans(0);
    assertThat(resourceSpans.getResource().getAttributesList()).contains(KeyValue.newBuilder().setKey(ResourceAttributes.SERVICE_NAME.getKey()).setValue(AnyValue.newBuilder().setStringValue("integration test").build()).build());
    assertThat(resourceSpans.getInstrumentationLibrarySpansCount()).isEqualTo(1);
    InstrumentationLibrarySpans ilSpans = resourceSpans.getInstrumentationLibrarySpans(0);
    assertThat(ilSpans.getInstrumentationLibrary().getName()).isEqualTo(OtlpExporterIntegrationTest.class.getName());
    assertThat(ilSpans.getSpansCount()).isEqualTo(1);
    io.opentelemetry.proto.trace.v1.Span protoSpan = ilSpans.getSpans(0);
    assertThat(protoSpan.getTraceId().toByteArray()).isEqualTo(span.getSpanContext().getTraceIdBytes());
    assertThat(protoSpan.getSpanId().toByteArray()).isEqualTo(span.getSpanContext().getSpanIdBytes());
    assertThat(protoSpan.getName()).isEqualTo("my span name");
    assertThat(protoSpan.getAttributesList()).isEqualTo(Collections.singletonList(KeyValue.newBuilder().setKey("key").setValue(AnyValue.newBuilder().setStringValue("value").build()).build()));
    assertThat(protoSpan.getEventsCount()).isEqualTo(1);
    assertThat(protoSpan.getEvents(0).getName()).isEqualTo("event");
    assertThat(protoSpan.getLinksCount()).isEqualTo(1);
    Link link = protoSpan.getLinks(0);
    assertThat(link.getTraceId().toByteArray()).isEqualTo(linkContext.getTraceIdBytes());
    assertThat(link.getSpanId().toByteArray()).isEqualTo(linkContext.getSpanIdBytes());
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanContext(io.opentelemetry.api.trace.SpanContext) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.api.trace.Span) Link(io.opentelemetry.proto.trace.v1.Span.Link)

Aggregations

InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)8 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)8 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)5 InstrumentationLibrary (io.opentelemetry.proto.common.v1.InstrumentationLibrary)3 Span (io.opentelemetry.proto.trace.v1.Span)3 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Attributes (io.opentelemetry.api.common.Attributes)2 SpanContext (io.opentelemetry.api.trace.SpanContext)2 Resource (io.opentelemetry.proto.resource.v1.Resource)2 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)2 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 ImmutableMap (com.google.common.collect.ImmutableMap)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 AttributeKey.booleanArrayKey (io.opentelemetry.api.common.AttributeKey.booleanArrayKey)1 AttributeKey.doubleArrayKey (io.opentelemetry.api.common.AttributeKey.doubleArrayKey)1 AttributeKey.longArrayKey (io.opentelemetry.api.common.AttributeKey.longArrayKey)1 AttributeKey.stringArrayKey (io.opentelemetry.api.common.AttributeKey.stringArrayKey)1