Search in sources :

Example 16 with KeyValue

use of io.opentelemetry.proto.common.v1.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();
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue)

Example 17 with KeyValue

use of io.opentelemetry.proto.common.v1.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;
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) List(java.util.List) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with KeyValue

use of io.opentelemetry.proto.common.v1.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();
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) AnyValue(io.opentelemetry.proto.common.v1.AnyValue) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) ArrayValue(io.opentelemetry.proto.common.v1.ArrayValue)

Example 19 with KeyValue

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