Search in sources :

Example 81 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanEventViewGeneratorTest method testExitCallsInfo.

@Test
public void testExitCallsInfo() {
    StructuredTrace.Builder traceBuilder = StructuredTrace.newBuilder();
    traceBuilder.setCustomerId("customer1").setTraceId(ByteBuffer.wrap("sample-trace-id".getBytes())).setEntityList(Collections.singletonList(Entity.newBuilder().setCustomerId("customer1").setEntityId("sample-entity-id").setEntityName("sample-entity-name").setEntityType("SERVICE").build())).setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(Maps.newHashMap())).build())).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setEntityEdgeList(new ArrayList<>()).setEventEdgeList(new ArrayList<>()).setEntityEventEdgeList(new ArrayList<>()).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis());
    StructuredTrace trace = traceBuilder.build();
    SpanEventViewGenerator spanEventViewGenerator = new SpanEventViewGenerator();
    List<SpanEventView> list = spanEventViewGenerator.process(trace);
    assertEquals(Maps.newHashMap(), list.get(0).getApiCalleeNameCount());
    assertEquals(0, list.get(0).getApiExitCalls());
    Map<String, AttributeValue> spanAttributes = new HashMap<>();
    spanAttributes.put(EnrichedSpanConstants.API_EXIT_CALLS_ATTRIBUTE, AttributeValue.newBuilder().setValue("5").build());
    Map<String, String> calleeNameCount = Map.of("service1", "5", "backend1", "2");
    spanAttributes.put(EnrichedSpanConstants.API_CALLEE_NAME_COUNT_ATTRIBUTE, AttributeValue.newBuilder().setValueMap(calleeNameCount).build());
    spanAttributes.put(EnrichedSpanConstants.getValue(Api.API_BOUNDARY_TYPE), AttributeValueCreator.create(EnrichedSpanConstants.getValue(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_ENTRY)));
    traceBuilder.setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(spanAttributes)).build())).build();
    trace = traceBuilder.build();
    spanEventViewGenerator = new SpanEventViewGenerator();
    list = spanEventViewGenerator.process(trace);
    assertEquals(calleeNameCount, list.get(0).getApiCalleeNameCount());
    assertEquals(5, list.get(0).getApiExitCalls());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Test(org.junit.jupiter.api.Test)

Example 82 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class EventBuilder method buildEvent.

public static Event buildEvent(String tenantId, JaegerSpanInternalModel.Span jaegerSpan, Optional<String> tenantIdKey) {
    Event.Builder eventBuilder = fastNewBuilder(Event.Builder.class);
    eventBuilder.setCustomerId(tenantId);
    eventBuilder.setEventId(jaegerSpan.getSpanId().asReadOnlyByteBuffer());
    eventBuilder.setEventName(jaegerSpan.getOperationName());
    // time related stuff
    long startTimeMillis = Timestamps.toMillis(jaegerSpan.getStartTime());
    eventBuilder.setStartTimeMillis(startTimeMillis);
    long endTimeMillis = Timestamps.toMillis(Timestamps.add(jaegerSpan.getStartTime(), jaegerSpan.getDuration()));
    eventBuilder.setEndTimeMillis(endTimeMillis);
    // SPAN REFS
    List<JaegerSpanInternalModel.SpanRef> referencesList = jaegerSpan.getReferencesList();
    if (referencesList.size() > 0) {
        eventBuilder.setEventRefList(new ArrayList<>());
        // Convert the reflist to a set to remove duplicate references. This has been observed in the
        // field.
        Set<JaegerSpanInternalModel.SpanRef> referencesSet = new HashSet<>(referencesList);
        for (JaegerSpanInternalModel.SpanRef spanRef : referencesSet) {
            EventRef.Builder builder = fastNewBuilder(EventRef.Builder.class);
            builder.setTraceId(spanRef.getTraceId().asReadOnlyByteBuffer());
            builder.setEventId(spanRef.getSpanId().asReadOnlyByteBuffer());
            builder.setRefType(EventRefType.valueOf(spanRef.getRefType().toString()));
            eventBuilder.getEventRefList().add(builder.build());
        }
    }
    // span attributes to event attributes
    Map<String, AttributeValue> attributeFieldMap = new HashMap<>();
    eventBuilder.setAttributesBuilder(fastNewBuilder(Attributes.Builder.class).setAttributeMap(attributeFieldMap));
    List<JaegerSpanInternalModel.KeyValue> tagsList = jaegerSpan.getTagsList();
    // https://github.com/hypertrace/hypertrace/issues/245
    for (JaegerSpanInternalModel.KeyValue keyValue : tagsList) {
        // Convert all attributes to lower case so that we don't have to
        // deal with the case sensitivity across different layers in the
        // platform.
        String key = keyValue.getKey().toLowerCase();
        // Do not add the tenant id to the tags.
        if ((tenantIdKey.isPresent() && key.equals(tenantIdKey.get()))) {
            continue;
        }
        attributeFieldMap.put(key, JaegerHTTagsConverter.createFromJaegerKeyValue(keyValue));
    }
    // Jaeger Fields - flags, warnings, logs, jaeger service name in the Process
    JaegerFields.Builder jaegerFieldsBuilder = eventBuilder.getJaegerFieldsBuilder();
    // FLAGS
    jaegerFieldsBuilder.setFlags(jaegerSpan.getFlags());
    // WARNINGS
    ProtocolStringList warningsList = jaegerSpan.getWarningsList();
    if (warningsList.size() > 0) {
        jaegerFieldsBuilder.setWarnings(warningsList);
    }
    // Jaeger service name can come from either first class field in Span or the tag
    // `jaeger.servicename`
    String serviceName = !StringUtils.isEmpty(jaegerSpan.getProcess().getServiceName()) ? jaegerSpan.getProcess().getServiceName() : attributeFieldMap.containsKey(OLD_JAEGER_SERVICENAME_KEY) ? attributeFieldMap.get(OLD_JAEGER_SERVICENAME_KEY).getValue() : StringUtils.EMPTY;
    if (!StringUtils.isEmpty(serviceName)) {
        eventBuilder.setServiceName(serviceName);
        // in case `jaeger.servicename` is present in the map, remove it
        attributeFieldMap.remove(OLD_JAEGER_SERVICENAME_KEY);
        attributeFieldMap.put(RawSpanConstants.getValue(JaegerAttribute.JAEGER_ATTRIBUTE_SERVICE_NAME), AttributeValueCreator.create(serviceName));
    }
    // EVENT METRICS
    Map<String, MetricValue> metricMap = new HashMap<>();
    MetricValue durationMetric = fastNewBuilder(MetricValue.Builder.class).setValue((double) (endTimeMillis - startTimeMillis)).build();
    metricMap.put("Duration", durationMetric);
    eventBuilder.setMetrics(fastNewBuilder(Metrics.Builder.class).setMetricMap(metricMap).build());
    return eventBuilder.build();
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) JaegerSpanInternalModel(io.jaegertracing.api_v2.JaegerSpanInternalModel) AvroBuilderCache.fastNewBuilder(org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder) Attributes(org.hypertrace.core.datamodel.Attributes) MetricValue(org.hypertrace.core.datamodel.MetricValue) EventRef(org.hypertrace.core.datamodel.EventRef) HashSet(java.util.HashSet) ProtocolStringList(com.google.protobuf.ProtocolStringList) JaegerFields(org.hypertrace.core.datamodel.eventfields.jaeger.JaegerFields) Event(org.hypertrace.core.datamodel.Event)

Example 83 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class RpcSemanticConventionUtilsTest method testGetGrpcRequestSizePriority.

@Test
public void testGetGrpcRequestSizePriority() {
    Map<String, AttributeValue> tagsMap = new HashMap<>() {

        {
            put(RawSpanConstants.getValue(ENVOY_REQUEST_SIZE), AttributeValue.newBuilder().setValue("1").build());
            put(RPC_REQUEST_METADATA_CONTENT_LENGTH.getValue(), AttributeValue.newBuilder().setValue("2").build());
            put(RawSpanConstants.getValue(GRPC_REQUEST_BODY), AttributeValue.newBuilder().setValue("some grpc request body").build());
            put(RPC_REQUEST_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc request body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    Event event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(1), RpcSemanticConventionUtils.getGrpcRequestSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RPC_REQUEST_METADATA_CONTENT_LENGTH.getValue(), AttributeValue.newBuilder().setValue("2").build());
            put(RawSpanConstants.getValue(GRPC_REQUEST_BODY), AttributeValue.newBuilder().setValue("some grpc request body").build());
            put(RPC_REQUEST_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc request body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(2), RpcSemanticConventionUtils.getGrpcRequestSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RawSpanConstants.getValue(GRPC_REQUEST_BODY), AttributeValue.newBuilder().setValue("some grpc request body").build());
            put(RPC_REQUEST_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc request body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(22), RpcSemanticConventionUtils.getGrpcRequestSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RPC_REQUEST_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc request body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(21), RpcSemanticConventionUtils.getGrpcRequestSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RPC_REQUEST_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc request body").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.empty(), RpcSemanticConventionUtils.getGrpcRequestSize(event));
    // test truncated grpc request body
    tagsMap = new HashMap<>() {

        {
            put(RawSpanConstants.getValue(GRPC_REQUEST_BODY), AttributeValue.newBuilder().setValue("some grpc request body").build());
            put(RawSpanConstants.getValue(GRPC_REQUEST_BODY_TRUNCATED), AttributeValue.newBuilder().setValue("true").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.empty(), RpcSemanticConventionUtils.getGrpcRequestSize(event));
    // test truncated rpc request body
    tagsMap = new HashMap<>() {

        {
            put(RPC_REQUEST_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc request body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
            put(RPC_REQUEST_BODY_TRUNCATED.getValue(), AttributeValue.newBuilder().setValue("true").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.empty(), RpcSemanticConventionUtils.getGrpcRequestSize(event));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 84 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class RpcSemanticConventionUtilsTest method testGetGrpcResponseSizePriority.

@Test
public void testGetGrpcResponseSizePriority() {
    Map<String, AttributeValue> tagsMap = new HashMap<>() {

        {
            put(RawSpanConstants.getValue(ENVOY_RESPONSE_SIZE), AttributeValue.newBuilder().setValue("1").build());
            put(RPC_RESPONSE_METADATA_CONTENT_LENGTH.getValue(), AttributeValue.newBuilder().setValue("2").build());
            put(RawSpanConstants.getValue(GRPC_RESPONSE_BODY), AttributeValue.newBuilder().setValue("some grpc response body").build());
            put(RPC_RESPONSE_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc response body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    Event event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(1), RpcSemanticConventionUtils.getGrpcResponseSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RPC_RESPONSE_METADATA_CONTENT_LENGTH.getValue(), AttributeValue.newBuilder().setValue("2").build());
            put(RawSpanConstants.getValue(GRPC_RESPONSE_BODY), AttributeValue.newBuilder().setValue("some grpc response body").build());
            put(RPC_RESPONSE_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc response body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(2), RpcSemanticConventionUtils.getGrpcResponseSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RawSpanConstants.getValue(GRPC_RESPONSE_BODY), AttributeValue.newBuilder().setValue("some grpc response body").build());
            put(RPC_RESPONSE_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc response body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(23), RpcSemanticConventionUtils.getGrpcResponseSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RPC_RESPONSE_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc response body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.of(22), RpcSemanticConventionUtils.getGrpcResponseSize(event));
    tagsMap = new HashMap<>() {

        {
            put(RPC_RESPONSE_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc response body").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.empty(), RpcSemanticConventionUtils.getGrpcResponseSize(event));
    // test truncated grpc response body
    tagsMap = new HashMap<>() {

        {
            put(RawSpanConstants.getValue(GRPC_RESPONSE_BODY), AttributeValue.newBuilder().setValue("some grpc response body").build());
            put(RawSpanConstants.getValue(GRPC_RESPONSE_BODY_TRUNCATED), AttributeValue.newBuilder().setValue("true").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.empty(), RpcSemanticConventionUtils.getGrpcResponseSize(event));
    // test truncated rpc response body
    tagsMap = new HashMap<>() {

        {
            put(RPC_RESPONSE_BODY.getValue(), AttributeValue.newBuilder().setValue("some rpc response body").build());
            put("rpc.system", AttributeValue.newBuilder().setValue("grpc").build());
            put(RPC_RESPONSE_BODY_TRUNCATED.getValue(), AttributeValue.newBuilder().setValue("true").build());
        }
    };
    event = mock(Event.class);
    when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(tagsMap).build());
    assertEquals(Optional.empty(), RpcSemanticConventionUtils.getGrpcResponseSize(event));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1