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();
}
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;
}
Aggregations