Search in sources :

Example 1 with BackendType

use of org.hypertrace.traceenricher.enrichment.enrichers.BackendType in project hypertrace-ingester by hypertrace.

the class AbstractBackendEntityEnricher method resolve.

@VisibleForTesting
public Optional<BackendInfo> resolve(Event event, StructuredTrace trace, StructuredTraceGraph structuredTraceGraph) {
    for (BackendProvider backendProvider : getBackendProviders()) {
        backendProvider.init(event);
        if (!backendProvider.isValidBackend(event)) {
            continue;
        }
        BackendType type = backendProvider.getBackendType(event);
        Optional<String> maybeBackendUri = backendProvider.getBackendUri(event, structuredTraceGraph);
        if (maybeBackendUri.isEmpty() || StringUtils.isEmpty(maybeBackendUri.get())) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Unable to infer backend uri from event {} for backend type {}", HexUtils.getHex(event.getEventId()), type);
            }
            continue;
        }
        String backendUri = maybeBackendUri.get();
        final Builder entityBuilder = getBackendEntityBuilder(type, backendUri, event, trace);
        backendProvider.getEntityAttributes(event).forEach(entityBuilder::putAttributes);
        Map<String, org.hypertrace.core.datamodel.AttributeValue> enrichedAttributes = new HashMap<>();
        Optional<String> backendOperation = backendProvider.getBackendOperation(event);
        Optional<String> backendDestination = backendProvider.getBackendDestination(event);
        backendOperation.ifPresent(operation -> enrichedAttributes.put(BACKEND_OPERATION_ATTR, AttributeValueCreator.create(operation)));
        backendDestination.ifPresent(destination -> enrichedAttributes.put(BACKEND_DESTINATION_ATTR, AttributeValueCreator.create(destination)));
        return Optional.of(new BackendInfo(entityBuilder.build(), Collections.unmodifiableMap(enrichedAttributes)));
    }
    return Optional.empty();
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Builder(org.hypertrace.entity.data.service.v1.Entity.Builder) BackendProvider(org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider) BackendType(org.hypertrace.traceenricher.enrichment.enrichers.BackendType) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with BackendType

use of org.hypertrace.traceenricher.enrichment.enrichers.BackendType in project hypertrace-ingester by hypertrace.

the class AbstractBackendEntityEnricher method isValidBackendEntity.

/**
 * Checks if the candidateEntity is indeed a backend Entity
 */
private boolean isValidBackendEntity(StructuredTrace trace, Event backendSpan, BackendInfo candidateInfo) {
    // Always create backend entity for RabbitMq, Mongo, Redis, Jdbc
    String backendProtocol = candidateInfo.getEntity().getIdentifyingAttributesMap().get(BACKEND_PROTOCOL_ATTR_NAME).getValue().getString();
    BackendType backendType = BackendType.valueOf(backendProtocol);
    if (backendType != BackendType.HTTP && backendType != BackendType.HTTPS && backendType != BackendType.GRPC) {
        return true;
    }
    // If there is a Service with the same FQN, then it isn't a Backend
    String fqn = candidateInfo.getEntity().getIdentifyingAttributesMap().get(BACKEND_HOST_ATTR_NAME).getValue().getString();
    if (checkIfServiceEntityExists(trace, backendSpan, fqn, candidateInfo.getEntity())) {
        return false;
    }
    // checks the existence of peer service in case if it is a partial trace, and we are missing
    // its immediate child span.
    String peerServiceName = SpanSemanticConventionUtils.getPeerServiceName(backendSpan);
    if (peerServiceName != null && checkIfServiceEntityExists(trace, backendSpan, peerServiceName, candidateInfo.getEntity())) {
        return false;
    }
    return true;
}
Also used : BackendType(org.hypertrace.traceenricher.enrichment.enrichers.BackendType)

Aggregations

BackendType (org.hypertrace.traceenricher.enrichment.enrichers.BackendType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)1 Builder (org.hypertrace.entity.data.service.v1.Entity.Builder)1 BackendProvider (org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider)1 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)1