use of io.opentelemetry.proto.common.v1.KeyValue in project data-prepper by opensearch-project.
the class RawLinkTest method testRawEventWithAttributes.
@Test
public void testRawEventWithAttributes() throws DecoderException {
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 Span.Link spanLink = Span.Link.newBuilder().setSpanId(ByteString.copyFrom(TestUtils.getRandomBytes(8))).setTraceId(ByteString.copyFrom(TestUtils.getRandomBytes(16))).setTraceState("Some State").addAllAttributes(Arrays.asList(childAttr1, childAttr2)).build();
final RawLink rawLink = RawLink.buildRawLink(spanLink);
assertThat(rawLink.getAttributes().size() == 2).isTrue();
assertThat((Long) rawLink.getAttributes().get(childAttr1.getKey()) == childAttr1.getValue().getIntValue()).isTrue();
assertThat(rawLink.getAttributes().get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr2.getKey())).equals(childAttr2.getValue().getStringValue())).isTrue();
assertThat(rawLink.getTraceState().equals("Some State")).isTrue();
assertThat(ByteString.copyFrom(Hex.decodeHex(rawLink.getTraceId())).equals(spanLink.getTraceId())).isTrue();
assertThat(ByteString.copyFrom(Hex.decodeHex(rawLink.getSpanId())).equals(spanLink.getSpanId())).isTrue();
}
use of io.opentelemetry.proto.common.v1.KeyValue in project inspectit-ocelot by inspectIT.
the class OcelotSpanUtils method toAttributeKey.
/**
* @return Returns a {@link AttributeKey} which represents the given {@link KeyValue}.
*/
private static AttributeKey<?> toAttributeKey(KeyValue attribute) {
String key = attribute.getKey();
AnyValue.ValueCase valueCase = attribute.getValue().getValueCase();
switch(valueCase) {
case STRING_VALUE:
return AttributeKey.stringKey(key);
case BOOL_VALUE:
return AttributeKey.booleanKey(key);
case INT_VALUE:
return AttributeKey.longKey(key);
case DOUBLE_VALUE:
return AttributeKey.doubleKey(key);
case ARRAY_VALUE:
return AttributeKey.stringArrayKey(key);
}
return null;
}
use of io.opentelemetry.proto.common.v1.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtilsTest method transformSpanConvertsResourceAttributesToAnnotations.
@Test
public void transformSpanConvertsResourceAttributesToAnnotations() {
List<KeyValue> resourceAttrs = Collections.singletonList(otlpAttribute("r-key", "r-value"));
wavefront.report.Span expectedSpan = OtlpTestHelpers.wfSpanGenerator(Collections.singletonList(new Annotation("r-key", "r-value"))).build();
actualSpan = OtlpProtobufUtils.transformSpan(OtlpTestHelpers.otlpSpanGenerator().build(), resourceAttrs, null, null, "test-source");
assertWFSpanEquals(expectedSpan, actualSpan);
}
use of io.opentelemetry.proto.common.v1.KeyValue in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtilsTest method transformSpanGivesSpanAttributesHigherPrecedenceThanResourceAttributes.
@Test
public void transformSpanGivesSpanAttributesHigherPrecedenceThanResourceAttributes() {
String key = "the-key";
Span otlpSpan = OtlpTestHelpers.otlpSpanGenerator().addAttributes(otlpAttribute(key, "span-value")).build();
List<KeyValue> resourceAttrs = Collections.singletonList(otlpAttribute(key, "rsrc-value"));
actualSpan = OtlpProtobufUtils.transformSpan(otlpSpan, resourceAttrs, null, null, "test-source");
assertThat(actualSpan.getAnnotations(), not(hasItem(new Annotation(key, "rsrc-value"))));
assertThat(actualSpan.getAnnotations(), hasItem(new Annotation(key, "span-value")));
}
use of io.opentelemetry.proto.common.v1.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);
}
Aggregations