Search in sources :

Example 6 with InstrumentationLibrary

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

the class OtlpProtobufUtilsTest method transformSpanHandlesInstrumentationLibrary.

@Test
public void transformSpanHandlesInstrumentationLibrary() {
    InstrumentationLibrary library = InstrumentationLibrary.newBuilder().setName("grpc").setVersion("1.0").build();
    Span otlpSpan = OtlpTestHelpers.otlpSpanGenerator().build();
    actualSpan = OtlpProtobufUtils.transformSpan(otlpSpan, emptyAttrs, library, null, "test-source");
    assertThat(actualSpan.getAnnotations(), hasItem(new Annotation("otel.scope.name", "grpc")));
    assertThat(actualSpan.getAnnotations(), hasItem(new Annotation("otel.scope.version", "1.0")));
}
Also used : Span(io.opentelemetry.proto.trace.v1.Span) Annotation(wavefront.report.Annotation) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with InstrumentationLibrary

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

the class OtlpProtobufUtilsTest method annotationsFromInstrumentationLibraryWithNullOrEmptyLibrary.

@Test
public void annotationsFromInstrumentationLibraryWithNullOrEmptyLibrary() {
    assertEquals(Collections.emptyList(), OtlpProtobufUtils.annotationsFromInstrumentationLibrary(null));
    InstrumentationLibrary emptyLibrary = InstrumentationLibrary.newBuilder().build();
    assertEquals(Collections.emptyList(), OtlpProtobufUtils.annotationsFromInstrumentationLibrary(emptyLibrary));
}
Also used : InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with InstrumentationLibrary

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

the class OtlpProtobufUtilsTest method annotationsFromInstrumentationLibraryWithLibraryData.

@Test
public void annotationsFromInstrumentationLibraryWithLibraryData() {
    InstrumentationLibrary library = InstrumentationLibrary.newBuilder().setName("net/http").build();
    assertEquals(Collections.singletonList(new Annotation("otel.scope.name", "net/http")), OtlpProtobufUtils.annotationsFromInstrumentationLibrary(library));
    library = library.toBuilder().setVersion("1.0.0").build();
    assertEquals(Arrays.asList(new Annotation("otel.scope.name", "net/http"), new Annotation("otel.scope.version", "1.0.0")), OtlpProtobufUtils.annotationsFromInstrumentationLibrary(library));
}
Also used : Annotation(wavefront.report.Annotation) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with InstrumentationLibrary

use of io.opentelemetry.proto.common.v1.InstrumentationLibrary in project java 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)

Example 10 with InstrumentationLibrary

use of io.opentelemetry.proto.common.v1.InstrumentationLibrary in project java by wavefrontHQ.

the class OtlpProtobufUtilsTest method annotationsFromInstrumentationLibraryWithNullOrEmptyLibrary.

@Test
public void annotationsFromInstrumentationLibraryWithNullOrEmptyLibrary() {
    assertEquals(Collections.emptyList(), OtlpProtobufUtils.annotationsFromInstrumentationLibrary(null));
    InstrumentationLibrary emptyLibrary = InstrumentationLibrary.newBuilder().build();
    assertEquals(Collections.emptyList(), OtlpProtobufUtils.annotationsFromInstrumentationLibrary(emptyLibrary));
}
Also used : InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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