use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtilsTest method transformSpanSetsSourceFromResourceAttributesNotSpanAttributes.
@Test
public void transformSpanSetsSourceFromResourceAttributesNotSpanAttributes() {
List<KeyValue> resourceAttrs = Collections.singletonList(otlpAttribute("source", "a-src"));
Span otlpSpan = OtlpTestHelpers.otlpSpanGenerator().addAttributes(otlpAttribute("source", "span-level")).build();
actualSpan = OtlpProtobufUtils.transformSpan(otlpSpan, resourceAttrs, null, null, "ignored");
assertEquals("a-src", actualSpan.getSource());
assertThat(actualSpan.getAnnotations(), not(hasItem(new Annotation("source", "a-src"))));
assertThat(actualSpan.getAnnotations(), hasItem(new Annotation("_source", "span-level")));
}
use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtilsTest method testAnnotationsFromArrayAttributes.
@Test
public void testAnnotationsFromArrayAttributes() {
KeyValue intArrayAttr = KeyValue.newBuilder().setKey("int-array").setValue(AnyValue.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(Arrays.asList(AnyValue.newBuilder().setIntValue(-1).build(), AnyValue.newBuilder().setIntValue(0).build(), AnyValue.newBuilder().setIntValue(1).build())).build()).build()).build();
KeyValue boolArrayAttr = KeyValue.newBuilder().setKey("bool-array").setValue(AnyValue.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(Arrays.asList(AnyValue.newBuilder().setBoolValue(true).build(), AnyValue.newBuilder().setBoolValue(false).build(), AnyValue.newBuilder().setBoolValue(true).build())).build()).build()).build();
KeyValue dblArrayAttr = KeyValue.newBuilder().setKey("dbl-array").setValue(AnyValue.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(Arrays.asList(AnyValue.newBuilder().setDoubleValue(-3.14).build(), AnyValue.newBuilder().setDoubleValue(0.0).build(), AnyValue.newBuilder().setDoubleValue(3.14).build())).build()).build()).build();
List<KeyValue> attributes = Arrays.asList(intArrayAttr, boolArrayAttr, dblArrayAttr);
List<Annotation> wfAnnotations = OtlpProtobufUtils.annotationsFromAttributes(attributes);
Map<String, String> wfAnnotationAsMap = getWfAnnotationAsMap(wfAnnotations);
assertEquals("[-1, 0, 1]", wfAnnotationAsMap.get("int-array"));
assertEquals("[true, false, true]", wfAnnotationAsMap.get("bool-array"));
assertEquals("[-3.14, 0.0, 3.14]", wfAnnotationAsMap.get("dbl-array"));
}
use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtilsTest method testAnnotationsFromSimpleAttributes.
@Test
public void testAnnotationsFromSimpleAttributes() {
KeyValue emptyAttr = KeyValue.newBuilder().setKey("empty").build();
KeyValue booleanAttr = KeyValue.newBuilder().setKey("a-boolean").setValue(AnyValue.newBuilder().setBoolValue(true).build()).build();
KeyValue stringAttr = KeyValue.newBuilder().setKey("a-string").setValue(AnyValue.newBuilder().setStringValue("a-value").build()).build();
KeyValue intAttr = KeyValue.newBuilder().setKey("a-int").setValue(AnyValue.newBuilder().setIntValue(1234).build()).build();
KeyValue doubleAttr = KeyValue.newBuilder().setKey("a-double").setValue(AnyValue.newBuilder().setDoubleValue(2.1138).build()).build();
KeyValue bytesAttr = KeyValue.newBuilder().setKey("a-bytes").setValue(AnyValue.newBuilder().setBytesValue(ByteString.copyFromUtf8("any + old & data")).build()).build();
KeyValue noValueAttr = KeyValue.newBuilder().setKey("no-value").setValue(AnyValue.newBuilder().build()).build();
List<KeyValue> attributes = Arrays.asList(emptyAttr, booleanAttr, stringAttr, intAttr, doubleAttr, noValueAttr, bytesAttr);
List<Annotation> wfAnnotations = OtlpProtobufUtils.annotationsFromAttributes(attributes);
Map<String, String> wfAnnotationAsMap = getWfAnnotationAsMap(wfAnnotations);
assertEquals(attributes.size(), wfAnnotationAsMap.size());
assertEquals("", wfAnnotationAsMap.get("empty"));
assertEquals("true", wfAnnotationAsMap.get("a-boolean"));
assertEquals("a-value", wfAnnotationAsMap.get("a-string"));
assertEquals("1234", wfAnnotationAsMap.get("a-int"));
assertEquals("2.1138", wfAnnotationAsMap.get("a-double"));
assertEquals("YW55ICsgb2xkICYgZGF0YQ==", wfAnnotationAsMap.get("a-bytes"));
assertEquals("<Unknown OpenTelemetry attribute value type VALUE_NOT_SET>", wfAnnotationAsMap.get("no-value"));
}
use of com.vmware.vim25.KeyValue in project data-prepper by opensearch-project.
the class OTelProtoHelperTest method testKeyValueListAsResourceAttributes.
/**
* Below object has a KeyValue with a key mapped to KeyValueList and is part of the resource attributes
*
* @throws JsonProcessingException
*/
@Test
public void testKeyValueListAsResourceAttributes() throws JsonProcessingException {
final KeyValue childAttr1 = KeyValue.newBuilder().setKey("ec2.instances").setValue(AnyValue.newBuilder().setIntValue(20).build()).build();
final KeyValue childAttr2 = KeyValue.newBuilder().setKey("ec2.instance.az").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
final KeyValue spanAttribute1 = KeyValue.newBuilder().setKey("aws.details").setValue(AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2)).build()).build()).build();
final KeyValue spanAttribute2 = KeyValue.newBuilder().setKey("service.name").setValue(AnyValue.newBuilder().setStringValue("EaglesService").build()).build();
final Map<String, Object> actual = OTelProtoHelper.getResourceAttributes(Resource.newBuilder().addAllAttributes(Arrays.asList(spanAttribute1, spanAttribute2)).build());
assertThat(actual.get(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute2.getKey())).equals(spanAttribute2.getValue().getStringValue())).isTrue();
assertThat(actual.containsKey(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey()))).isTrue();
final Map<String, Object> actualValue = returnMap((String) actual.get(OTelProtoHelper.RESOURCE_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();
}
use of com.vmware.vim25.KeyValue in project data-prepper by opensearch-project.
the class OTelProtoHelperTest method testArrayOfValueAsResourceAttributes.
/**
* Below object has a KeyValue with a key mapped to KeyValueList and is part of the span attributes
*
* @throws JsonProcessingException
*/
@Test
public void testArrayOfValueAsResourceAttributes() throws JsonProcessingException {
final KeyValue childAttr1 = KeyValue.newBuilder().setKey("ec2.instances").setValue(AnyValue.newBuilder().setIntValue(20).build()).build();
final KeyValue childAttr2 = KeyValue.newBuilder().setKey("ec2.instance.az").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
final AnyValue anyValue1 = AnyValue.newBuilder().setStringValue(UUID.randomUUID().toString()).build();
final AnyValue anyValue2 = AnyValue.newBuilder().setDoubleValue(2000.123).build();
final AnyValue anyValue3 = AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2))).build();
final ArrayValue arrayValue = ArrayValue.newBuilder().addAllValues(Arrays.asList(anyValue1, anyValue2, anyValue3)).build();
final KeyValue spanAttribute1 = KeyValue.newBuilder().setKey("aws.details").setValue(AnyValue.newBuilder().setArrayValue(arrayValue)).build();
final Map<String, Object> actual = OTelProtoHelper.getResourceAttributes(Resource.newBuilder().addAllAttributes(Collections.singletonList(spanAttribute1)).build());
assertThat(actual.containsKey(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey()))).isTrue();
final List<Object> actualValue = returnList((String) actual.get(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey())));
assertThat((actualValue.get(0)).equals(anyValue1.getStringValue())).isTrue();
assertThat(((Double) actualValue.get(1)) == (anyValue2.getDoubleValue())).isTrue();
final Map<String, Object> map = returnMap((String) actualValue.get(2));
assertThat((Integer) map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == childAttr1.getValue().getIntValue()).isTrue();
assertThat(map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr2.getKey())).equals(childAttr2.getValue().getStringValue())).isTrue();
assertThat((Integer) map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == (childAttr1.getValue().getIntValue())).isTrue();
}
Aggregations