Search in sources :

Example 71 with AttributeValue

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

the class RedisBackendProviderTest method checkBackendEntityGeneratedFromRedisEventOtelFormat.

@Test
public void checkBackendEntityGeneratedFromRedisEventOtelFormat() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of(OTelDbSemanticConventions.DB_SYSTEM.getValue(), buildAttributeValue(OTelDbSemanticConventions.REDIS_DB_SYSTEM_VALUE.getValue()), OTelDbSemanticConventions.DB_CONNECTION_STRING.getValue(), buildAttributeValue("redis-cart:6379"), OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), buildAttributeValue("redis-cart"), OTelSpanSemanticConventions.NET_PEER_PORT.getValue(), buildAttributeValue("6379"), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "k8s.pod_id", buildAttributeValue("55636196-c840-11e9-a417-42010a8a0064"), "db.operation", AttributeValue.newBuilder().setValue("GET").build(), "db.redis.database_index", AttributeValue.newBuilder().setValue("15").build(), "docker.container_id", buildAttributeValue("ee85cf2cfc3b24613a3da411fdbd2f3eabbe729a5c86c5262971c8d8c29dad0f"), "FLAGS", buildAttributeValue("0"))).build()).setEventName("reactive.redis.exit").setStartTimeMillis(1566869077746L).setEndTimeMillis(1566869077750L).setMetrics(Metrics.newBuilder().setMetricMap(Map.of("Duration", MetricValue.newBuilder().setValue(4.0).build())).build()).setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    final Entity backendEntity = backendInfo.getEntity();
    assertEquals("redis-cart:6379", backendEntity.getEntityName());
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString(), "REDIS");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString(), "redis-cart");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "6379");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "reactive.redis.exit");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("GET"), "BACKEND_DESTINATION", AttributeValueCreator.create("15")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 72 with AttributeValue

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

the class ApiBoundaryTypeAttributeEnricher method enrichEvent.

@Override
public void enrichEvent(StructuredTrace trace, Event event) {
    if (event.getEnrichedAttributes() == null) {
        return;
    }
    Map<String, AttributeValue> attributeMap = event.getEnrichedAttributes().getAttributeMap();
    if (attributeMap == null) {
        return;
    }
    boolean isEntrySpan = EnrichedSpanUtils.isEntrySpan(event);
    boolean isExitSpan = EnrichedSpanUtils.isExitSpan(event);
    // does not need to build the full traversal graph, just get the parents mapping
    StructuredTraceGraph graph = buildGraph(trace);
    if (isEntrySpan) {
        /*
      Determines if this is entry span is an entry to  api
      1. If the event is an ENTRY span, and
      2. If the direct parent span is either an EXIT Span or Null, or direct parent span service name differs from current span service name.
      */
        Event parentEvent = graph.getParentEvent(event);
        if (!EnrichedSpanUtils.isEntrySpan(parentEvent) || EnrichedSpanUtils.areBothSpansFromDifferentService(event, parentEvent)) {
            addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(ENTRY_BOUNDARY_TYPE));
            // For all API entry spans, try to enrich with host header.
            enrichHostHeader(event);
        }
    } else if (isExitSpan) {
        /*
      Determines if this is exit span is an exit to  api
      1. If the event is an EXIT span, and
      2. If the direct child span is either an ENTRY Span or Null, then this is the exit point.
      */
        List<Event> childrenEvents = graph.getChildrenEvents(event);
        if (childrenEvents == null || childrenEvents.isEmpty()) {
            addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(EXIT_BOUNDARY_TYPE));
        } else {
            for (Event childEvent : childrenEvents) {
                if (EnrichedSpanUtils.isEntrySpan(childEvent)) {
                    addEnrichedAttribute(event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(EXIT_BOUNDARY_TYPE));
                    break;
                }
            }
        }
    }
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph)

Example 73 with AttributeValue

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

the class HttpAttributeEnricher method enrichEvent.

@Override
public void enrichEvent(StructuredTrace trace, Event event) {
    EnrichedSpanUtils.getPath(event).ifPresent(path -> addEnrichedAttribute(event, HTTP_REQUEST_PATH_ATTR, AttributeValueCreator.create(path)));
    EnrichedSpanUtils.getQueryString(event).ifPresent(queryString -> {
        Map<String, List<String>> paramNameToValues = getQueryParamsFromQueryString(queryString);
        for (Map.Entry<String, List<String>> queryParamEntry : paramNameToValues.entrySet()) {
            if (queryParamEntry.getValue().isEmpty()) {
                continue;
            }
            String queryParamAttr = queryParamEntry.getKey();
            // Getting a single value out of all values(for backward compatibility)
            String queryParamStringValue = queryParamEntry.getValue().get(0);
            AttributeValue attributeValue = fastNewBuilder(AttributeValue.Builder.class).setValue(queryParamStringValue).setValueList(queryParamEntry.getValue()).build();
            addEnrichedAttribute(event, queryParamAttr, attributeValue);
        }
    });
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) AvroBuilderCache.fastNewBuilder(org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Map(java.util.Map)

Example 74 with AttributeValue

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

the class SpanTypeAttributeEnricher method enrichEvent.

@Override
public void enrichEvent(StructuredTrace trace, Event event) {
    if (event.getAttributes() == null) {
        return;
    }
    Map<String, AttributeValue> attributeMap = event.getAttributes().getAttributeMap();
    if (attributeMap == null) {
        return;
    }
    // Figure out if event is entry or exit based on other span attributes
    Boolean isEntry = null;
    if (attributeMap.containsKey(OTEL_SPAN_KIND)) {
        String spanKindValue = attributeMap.get(OTEL_SPAN_KIND).getValue();
        if (spanKindValue.equalsIgnoreCase(OTEL_SPAN_KIND_SERVER_VALUE) || spanKindValue.equalsIgnoreCase(OtelMessagingSemanticConventions.CONSUMER.getValue())) {
            isEntry = true;
        } else if (spanKindValue.equalsIgnoreCase(OTEL_SPAN_KIND_CLIENT_CLIENT) || spanKindValue.equalsIgnoreCase(OtelMessagingSemanticConventions.PRODUCER.getValue())) {
            isEntry = false;
        } else {
            LOGGER.debug("Unrecognized span_kind value: {}. Event: {}.", spanKindValue, event);
        }
    } else if (attributeMap.containsKey(SPAN_KIND_KEY)) {
        String spanKindValue = attributeMap.get(SPAN_KIND_KEY).getValue();
        if (spanKindValue.equalsIgnoreCase(SERVER_VALUE) || spanKindValue.equalsIgnoreCase(OtelMessagingSemanticConventions.CONSUMER.getValue())) {
            isEntry = true;
        } else if (spanKindValue.equalsIgnoreCase(CLIENT_VALUE) || spanKindValue.equalsIgnoreCase(OtelMessagingSemanticConventions.PRODUCER.getValue())) {
            isEntry = false;
        } else {
            LOGGER.debug("Unrecognized span.kind value: {}. Event: {}.", spanKindValue, event);
        }
    } else if (attributeMap.containsKey(CLIENT_KEY)) {
        String clientValue = attributeMap.get(CLIENT_KEY).getValue();
        if (clientValue.equalsIgnoreCase("false")) {
            isEntry = true;
        } else if (clientValue.equalsIgnoreCase("true")) {
            isEntry = false;
        } else {
            LOGGER.debug("Unrecognized Client value: {}. Event: {}.", clientValue, event);
        }
    } else if (attributeMap.containsKey(envoyOperationNameAttr)) {
        String spanType = attributeMap.get(envoyOperationNameAttr).getValue();
        if (StringUtils.equalsIgnoreCase(envoyIngressSpanValue, spanType)) {
            isEntry = true;
        } else if (StringUtils.equalsIgnoreCase(envoyEgressSpanValue, spanType)) {
            isEntry = false;
        } else {
            LOGGER.debug("Unrecognized envoyOperationNameAttr value: {}. Event: {}.", spanType, event);
        }
    } else if (StringUtils.startsWith(event.getEventName(), RawSpanConstants.getValue(SpanNamePrefix.SPAN_NAME_PREFIX_SENT))) {
        // Go Opencensus instrumentation seems to have this convention Sent. prefix
        // meaning client/exit/backend call
        isEntry = false;
    } else if (StringUtils.startsWith(event.getEventName(), RawSpanConstants.getValue(SpanNamePrefix.SPAN_NAME_PREFIX_RECV))) {
        isEntry = true;
    }
    // Add the new information as an enriched attribute, not raw attribute.
    if (isEntry == null) {
        addEnrichedAttribute(event, spanTypeAttrName, AttributeValueCreator.create(Constants.getEnrichedSpanConstant(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_UNSPECIFIED)));
    } else if (isEntry) {
        addEnrichedAttribute(event, spanTypeAttrName, AttributeValueCreator.create(Constants.getEnrichedSpanConstant(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_ENTRY)));
    } else {
        addEnrichedAttribute(event, spanTypeAttrName, AttributeValueCreator.create(Constants.getEnrichedSpanConstant(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_EXIT)));
    }
    // Get the protocol and name and create API entity based on the protocol.
    Protocol protocol = getProtocolName(event);
    addEnrichedAttribute(event, PROTOCOL_ATTR, AttributeValueCreator.create(Constants.getEnrichedSpanConstant(protocol)));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Protocol(org.hypertrace.traceenricher.enrichedspan.constants.v1.Protocol)

Example 75 with AttributeValue

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

the class TraceStatsEnricher method addHeadSpanIdTraceAttribute.

private void addHeadSpanIdTraceAttribute(StructuredTrace trace, Event headSpan) {
    AttributeValue attribute = fastNewBuilder(AttributeValue.Builder.class).setBinaryValue(headSpan.getEventId()).build();
    trace.getAttributes().getAttributeMap().put(HEAD_EVENT_ID, attribute);
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue)

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