Search in sources :

Example 1 with Backend

use of org.hypertrace.traceenricher.enrichedspan.constants.v1.Backend in project hypertrace-ingester by hypertrace.

the class AbstractBackendEntityEnricher method enrichTrace.

// At trace level, based on the next span to identify if a backend entity is actually a service
// entity.
@Override
public void enrichTrace(StructuredTrace trace) {
    try {
        StructuredTraceGraph structuredTraceGraph = buildGraph(trace);
        trace.getEventList().stream().filter(event -> EnrichedSpanUtils.isExitSpan(event) && SpanAttributeUtils.isLeafSpan(structuredTraceGraph, event) && canResolveBackend(structuredTraceGraph, event)).map(event -> Pair.of(event, resolve(event, trace, structuredTraceGraph))).filter(pair -> pair.getRight().isPresent()).filter(pair -> isValidBackendEntity(trace, pair.getLeft(), pair.getRight().get())).forEach(pair -> decorateWithBackendEntity(pair.getRight().get(), pair.getLeft(), trace));
    } catch (Exception ex) {
        LOGGER.error("An error occurred while enriching backend", ex);
    }
}
Also used : RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) EnrichedSpanUtils(org.hypertrace.traceenricher.enrichedspan.constants.utils.EnrichedSpanUtils) EntityConstants(org.hypertrace.entity.service.constants.EntityConstants) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) AttributeValueCreator(org.hypertrace.core.datamodel.shared.trace.AttributeValueCreator) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) LinkedHashMap(java.util.LinkedHashMap) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) Pair(org.apache.commons.lang3.tuple.Pair) BackendType(org.hypertrace.traceenricher.enrichment.enrichers.BackendType) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) Map(java.util.Map) BackendProvider(org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider) EnrichedSpanConstants(org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants) Entity(org.hypertrace.entity.data.service.v1.Entity) HexUtils(org.hypertrace.core.datamodel.shared.HexUtils) SpanAttributeUtils(org.hypertrace.core.datamodel.shared.SpanAttributeUtils) Backend(org.hypertrace.traceenricher.enrichedspan.constants.v1.Backend) EntityType(org.hypertrace.entity.v1.entitytype.EntityType) Nullable(javax.annotation.Nullable) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Logger(org.slf4j.Logger) SpanSemanticConventionUtils(org.hypertrace.semantic.convention.utils.span.SpanSemanticConventionUtils) Config(com.typesafe.config.Config) AbstractTraceEnricher(org.hypertrace.traceenricher.enrichment.AbstractTraceEnricher) BackendAttribute(org.hypertrace.entity.constants.v1.BackendAttribute) EnricherUtil(org.hypertrace.traceenricher.util.EnricherUtil) Event(org.hypertrace.core.datamodel.Event) EdsClient(org.hypertrace.entity.data.service.client.EdsClient) ClientRegistry(org.hypertrace.traceenricher.enrichment.clients.ClientRegistry) EntityCache(org.hypertrace.traceenricher.enrichment.enrichers.cache.EntityCache) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) EntityAvroConverter(org.hypertrace.traceenricher.util.EntityAvroConverter) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) Builder(org.hypertrace.entity.data.service.v1.Entity.Builder) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with Backend

use of org.hypertrace.traceenricher.enrichedspan.constants.v1.Backend in project hypertrace-ingester by hypertrace.

the class ServiceCallViewGenerator method getServiceCallFromSingleExitEvent.

private ServiceCallView getServiceCallFromSingleExitEvent(StructuredTrace trace, Event event) {
    ServiceCallView.Builder builder = createAndInitializeBuilder(trace);
    buildCommonServiceCallView(event, builder);
    Protocol protocol = EnrichedSpanUtils.getProtocol(event);
    buildExitSpanView(event, builder);
    // If the call was made into a backend, populate Backend specific data on the view.
    if (event.getEnrichedAttributes().getAttributeMap().containsKey(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_ID))) {
        buildExitSpanViewForBackendEntity(event, builder, protocol);
    }
    return builder.build();
}
Also used : ServiceCallView(org.hypertrace.viewgenerator.api.ServiceCallView) Protocol(org.hypertrace.traceenricher.enrichedspan.constants.v1.Protocol)

Example 3 with Backend

use of org.hypertrace.traceenricher.enrichedspan.constants.v1.Backend 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)

Aggregations

Protocol (org.hypertrace.traceenricher.enrichedspan.constants.v1.Protocol)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 Config (com.typesafe.config.Config)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nullable (javax.annotation.Nullable)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)1 Event (org.hypertrace.core.datamodel.Event)1 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)1 HexUtils (org.hypertrace.core.datamodel.shared.HexUtils)1 SpanAttributeUtils (org.hypertrace.core.datamodel.shared.SpanAttributeUtils)1 StructuredTraceGraph (org.hypertrace.core.datamodel.shared.StructuredTraceGraph)1