Search in sources :

Example 11 with KeyValue

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();
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) Span(io.opentelemetry.proto.trace.v1.Span) Test(org.junit.Test)

Example 12 with KeyValue

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;
}
Also used : AnyValue(io.opentelemetry.proto.common.v1.AnyValue) ByteString(com.google.protobuf.ByteString)

Example 13 with KeyValue

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);
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) Annotation(wavefront.report.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with KeyValue

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")));
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) ByteString(com.google.protobuf.ByteString) Span(io.opentelemetry.proto.trace.v1.Span) Annotation(wavefront.report.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with KeyValue

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);
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) Span(io.opentelemetry.proto.trace.v1.Span) Annotation(wavefront.report.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

KeyValue (io.opentelemetry.proto.common.v1.KeyValue)15 Test (org.junit.Test)11 ByteString (com.google.protobuf.ByteString)10 Annotation (wavefront.report.Annotation)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Span (io.opentelemetry.proto.trace.v1.Span)5 KeyValue (com.vmware.vim25.KeyValue)3 AnyValue (io.opentelemetry.proto.common.v1.AnyValue)3 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayValue (io.opentelemetry.proto.common.v1.ArrayValue)2 KeyAnyValue (com.vmware.vim25.KeyAnyValue)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 OvfCreateImportSpecResult (com.vmware.vim25.OvfCreateImportSpecResult)1 OvfNetworkMapping (com.vmware.vim25.OvfNetworkMapping)1 MorObjectHandler (io.cloudslang.content.vmware.services.helpers.MorObjectHandler)1 VmUtils (io.cloudslang.content.vmware.services.utils.VmUtils)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 List (java.util.List)1 Map (java.util.Map)1