Search in sources :

Example 11 with InstrumentationLibrary

use of io.opentelemetry.proto.common.v1.InstrumentationLibrary in project data-prepper by opensearch-project.

the class OTelProtoHelperTest method testInstrumentationLibraryAttributes.

@Test
public void testInstrumentationLibraryAttributes() {
    final InstrumentationLibrary il1 = InstrumentationLibrary.newBuilder().setName("Jaeger").setVersion("0.6.0").build();
    final InstrumentationLibrary il2 = InstrumentationLibrary.newBuilder().setName("Jaeger").build();
    final InstrumentationLibrary il3 = InstrumentationLibrary.newBuilder().setVersion("0.6.0").build();
    final InstrumentationLibrary il4 = InstrumentationLibrary.newBuilder().build();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il1).size() == 2).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il1).get(OTelProtoHelper.INSTRUMENTATION_LIBRARY_NAME).equals(il1.getName())).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il1).get(OTelProtoHelper.INSTRUMENTATION_LIBRARY_VERSION).equals(il1.getVersion())).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il2).size() == 1).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il2).get(OTelProtoHelper.INSTRUMENTATION_LIBRARY_NAME).equals(il2.getName())).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il3).size() == 1).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il3).get(OTelProtoHelper.INSTRUMENTATION_LIBRARY_VERSION).equals(il3.getVersion())).isTrue();
    assertThat(OTelProtoHelper.getInstrumentationLibraryAttributes(il4).isEmpty()).isTrue();
}
Also used : InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) Test(org.junit.Test)

Example 12 with InstrumentationLibrary

use of io.opentelemetry.proto.common.v1.InstrumentationLibrary in project wavefront-proxy by wavefrontHQ.

the class OtlpProtobufUtils method transformSpan.

@VisibleForTesting
static Span transformSpan(io.opentelemetry.proto.trace.v1.Span otlpSpan, List<KeyValue> resourceAttrs, InstrumentationLibrary iLibrary, ReportableEntityPreprocessor preprocessor, String defaultSource) {
    Pair<String, List<KeyValue>> sourceAndResourceAttrs = sourceFromAttributes(resourceAttrs, defaultSource);
    String source = sourceAndResourceAttrs._1;
    resourceAttrs = sourceAndResourceAttrs._2;
    // Order of arguments to Stream.of() matters: when a Resource Attribute and a Span Attribute
    // happen to share the same key, we want the Span Attribute to "win" and be preserved.
    List<KeyValue> otlpAttributes = Stream.of(resourceAttrs, otlpSpan.getAttributesList()).flatMap(Collection::stream).collect(Collectors.toList());
    List<Annotation> wfAnnotations = annotationsFromAttributes(otlpAttributes);
    wfAnnotations.add(SPAN_KIND_ANNOTATION_HASH_MAP.get(otlpSpan.getKind()));
    wfAnnotations.addAll(annotationsFromStatus(otlpSpan.getStatus()));
    wfAnnotations.addAll(annotationsFromInstrumentationLibrary(iLibrary));
    wfAnnotations.addAll(annotationsFromDroppedCounts(otlpSpan));
    wfAnnotations.addAll(annotationsFromTraceState(otlpSpan.getTraceState()));
    wfAnnotations.addAll(annotationsFromParentSpanID(otlpSpan.getParentSpanId()));
    String wfSpanId = SpanUtils.toStringId(otlpSpan.getSpanId());
    String wfTraceId = SpanUtils.toStringId(otlpSpan.getTraceId());
    long startTimeMs = TimeUnit.NANOSECONDS.toMillis(otlpSpan.getStartTimeUnixNano());
    long durationMs = otlpSpan.getEndTimeUnixNano() == 0 ? 0 : TimeUnit.NANOSECONDS.toMillis(otlpSpan.getEndTimeUnixNano() - otlpSpan.getStartTimeUnixNano());
    wavefront.report.Span toReturn = wavefront.report.Span.newBuilder().setName(otlpSpan.getName()).setSpanId(wfSpanId).setTraceId(wfTraceId).setStartMillis(startTimeMs).setDuration(durationMs).setAnnotations(wfAnnotations).setSource(source).setCustomer("dummy").build();
    // apply preprocessor
    if (preprocessor != null) {
        preprocessor.forSpan().transform(toReturn);
    }
    // After preprocessor has run `transform()`, set required WF tags that may still be missing
    List<Annotation> processedAnnotationList = setRequiredTags(toReturn.getAnnotations());
    toReturn.setAnnotations(processedAnnotationList);
    return toReturn;
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) List(java.util.List) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

InstrumentationLibrary (io.opentelemetry.proto.common.v1.InstrumentationLibrary)10 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Annotation (wavefront.report.Annotation)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ArrayList (java.util.ArrayList)4 InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)3 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)3 ByteString (com.google.protobuf.ByteString)2 KeyValue (io.opentelemetry.proto.common.v1.KeyValue)2 Resource (io.opentelemetry.proto.resource.v1.Resource)2 Span (io.opentelemetry.proto.trace.v1.Span)2 List (java.util.List)2 Span (wavefront.report.Span)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Attributes (io.opentelemetry.api.common.Attributes)1 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)1 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)1 Resource (io.opentelemetry.sdk.resources.Resource)1 OcelotSpanUtils (io.opentelemetry.sdk.trace.OcelotSpanUtils)1