use of org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider 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();
}
Aggregations