use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtilsTest method transformSpanHandlesSpanAttributes.
@Test
public void transformSpanHandlesSpanAttributes() {
Pair<ByteString, String> parentSpanIdPair = parentSpanIdPair();
KeyValue booleanAttr = KeyValue.newBuilder().setKey("a-boolean").setValue(AnyValue.newBuilder().setBoolValue(true).build()).build();
Span otlpSpan = OtlpTestHelpers.otlpSpanGenerator().addAttributes(booleanAttr).setParentSpanId(parentSpanIdPair._1).build();
List<Annotation> wfAttrs = Arrays.asList(Annotation.newBuilder().setKey("parent").setValue(parentSpanIdPair._2).build(), Annotation.newBuilder().setKey("a-boolean").setValue("true").build());
wavefront.report.Span expectedSpan = OtlpTestHelpers.wfSpanGenerator(wfAttrs).build();
actualSpan = OtlpProtobufUtils.transformSpan(otlpSpan, emptyAttrs, null, null, "test-source");
assertWFSpanEquals(expectedSpan, actualSpan);
}
use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpTestHelpers method otlpSpanEvent.
public static io.opentelemetry.proto.trace.v1.Span.Event otlpSpanEvent(int droppedAttrsCount) {
long eventTimestamp = TimeUnit.MILLISECONDS.toNanos(startTimeMs + (durationMs / 2));
KeyValue attr = otlpAttribute("attrKey", "attrValue");
io.opentelemetry.proto.trace.v1.Span.Event.Builder builder = io.opentelemetry.proto.trace.v1.Span.Event.newBuilder().setName("eventName").setTimeUnixNano(eventTimestamp).addAttributes(attr);
if (droppedAttrsCount > 0) {
builder.setDroppedAttributesCount(droppedAttrsCount);
}
return builder.build();
}
use of com.vmware.vim25.KeyValue 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;
}
use of com.vmware.vim25.KeyValue in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingExporterAccess method fromProto.
private static Attributes fromProto(List<KeyValue> attributes) {
AttributesBuilder converted = Attributes.builder();
for (KeyValue attribute : attributes) {
String key = attribute.getKey();
AnyValue value = attribute.getValue();
switch(value.getValueCase()) {
case STRING_VALUE:
converted.put(key, value.getStringValue());
break;
case BOOL_VALUE:
converted.put(key, value.getBoolValue());
break;
case INT_VALUE:
converted.put(key, value.getIntValue());
break;
case DOUBLE_VALUE:
converted.put(key, value.getDoubleValue());
break;
case ARRAY_VALUE:
ArrayValue array = value.getArrayValue();
if (array.getValuesCount() != 0) {
switch(array.getValues(0).getValueCase()) {
case STRING_VALUE:
converted.put(stringArrayKey(key), array.getValuesList().stream().map(AnyValue::getStringValue).collect(toList()));
break;
case BOOL_VALUE:
converted.put(booleanArrayKey(key), array.getValuesList().stream().map(AnyValue::getBoolValue).collect(toList()));
break;
case INT_VALUE:
converted.put(longArrayKey(key), array.getValuesList().stream().map(AnyValue::getIntValue).collect(toList()));
break;
case DOUBLE_VALUE:
converted.put(doubleArrayKey(key), array.getValuesList().stream().map(AnyValue::getDoubleValue).collect(toList()));
break;
case VALUE_NOT_SET:
break;
default:
throw new IllegalStateException("Unexpected attribute: " + array.getValues(0).getValueCase());
}
}
break;
case VALUE_NOT_SET:
break;
default:
throw new IllegalStateException("Unexpected attribute: " + value.getValueCase());
}
}
return converted.build();
}
use of com.vmware.vim25.KeyValue in project data-prepper by opensearch-project.
the class OTelProtoHelperTest method testKeyValueListAsSpanAttributes.
/**
* Below object has a KeyValue with a key mapped to KeyValueList and is part of the span attributes
*
* @throws JsonProcessingException
*/
@Test
public void testKeyValueListAsSpanAttributes() throws JsonProcessingException {
final KeyValue childAttr1 = KeyValue.newBuilder().setKey("statement").setValue(AnyValue.newBuilder().setIntValue(1_000).build()).build();
final KeyValue childAttr2 = KeyValue.newBuilder().setKey("statement.params").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
final KeyValue spanAttribute1 = KeyValue.newBuilder().setKey("db.details").setValue(AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2)).build()).build()).build();
final KeyValue spanAttribute2 = KeyValue.newBuilder().setKey("http.status").setValue(AnyValue.newBuilder().setStringValue("4xx").build()).build();
final Map<String, Object> actual = OTelProtoHelper.getSpanAttributes(Span.newBuilder().addAllAttributes(Arrays.asList(spanAttribute1, spanAttribute2)).build());
assertThat(actual.get(OTelProtoHelper.SPAN_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute2.getKey())).equals(spanAttribute2.getValue().getStringValue())).isTrue();
assertThat(actual.containsKey(OTelProtoHelper.SPAN_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey()))).isTrue();
final Map<String, Object> actualValue = returnMap((String) actual.get(OTelProtoHelper.SPAN_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey())));
assertThat((Integer) actualValue.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == childAttr1.getValue().getIntValue()).isTrue();
assertThat(actualValue.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr2.getKey())).equals(childAttr2.getValue().getStringValue())).isTrue();
}
Aggregations