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();
}
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;
}
Aggregations