use of org.hypertrace.entity.data.service.v1.AttributeValue in project zipkin-gcp by openzipkin.
the class AttributesExtractorTest method testLabelIsRenamed.
@Test
public void testLabelIsRenamed() {
Map<String, String> knownLabels = new LinkedHashMap<>();
knownLabels.put("known.1", "renamed.1");
knownLabels.put("known.2", "renamed.2");
AttributesExtractor extractor = new AttributesExtractor(knownLabels);
Span zipkinSpan = Span.newBuilder().traceId("4").name("test-span").id("5").addAnnotation(1, "annotation.key.1").addAnnotation(13, "known.1").putTag("tag.key.1", "value").putTag("known.2", "known.value").build();
Map<String, AttributeValue> labels = extractor.extract(zipkinSpan).getAttributeMapMap();
assertThat(labels).contains(entry("renamed.2", toAttributeValue("known.value")));
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.
the class AbstractBackendEntityEnricher method getAttributesToEnrich.
private Map<String, org.hypertrace.core.datamodel.AttributeValue> getAttributesToEnrich(Entity backend) {
Map<String, org.hypertrace.core.datamodel.AttributeValue> attributes = new LinkedHashMap<>();
attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_ID), AttributeValueCreator.create(backend.getEntityId()));
attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_NAME), AttributeValueCreator.create(backend.getEntityName()));
attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_HOST), createAttributeValue(backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_HOST))));
attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PORT), createAttributeValue(backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PORT))));
attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL), createAttributeValue(backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL))));
AttributeValue path = backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PATH));
if (path != null) {
attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PATH), createAttributeValue(path));
}
return attributes;
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.
the class EntityCache method loadServiceFromFQN.
protected Optional<Entity> loadServiceFromFQN(Pair<String, String> tenantIdFQNPair) {
AttributeValue fqnAttribute = AttributeValue.newBuilder().setValue(Value.newBuilder().setString(tenantIdFQNPair.getRight())).build();
ByTypeAndIdentifyingAttributes request = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), fqnAttribute).build();
return Optional.ofNullable(edsClient.getByTypeAndIdentifyingAttributes(tenantIdFQNPair.getLeft(), request));
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.
the class EndpointEnricher method enrichEvent.
@Override
public void enrichEvent(StructuredTrace trace, Event event) {
// This Enricher depends on SpanType so if that's missing, we can't do anything with the span.
if (event.getEnrichedAttributes() == null) {
return;
}
Map<String, AttributeValue> attributeMap = event.getEnrichedAttributes().getAttributeMap();
if (attributeMap == null || attributeMap.isEmpty()) {
return;
}
if (!EnrichedSpanUtils.isEntryApiBoundary(event)) {
return;
}
// Lookup the service id from the span. If we can't find a service id, we can't really
// associate API details with that span.
String serviceId = EnrichedSpanUtils.getServiceId(event);
String serviceName = EnrichedSpanUtils.getServiceName(event);
String customerId = trace.getCustomerId();
if (serviceId == null) {
LOGGER.warn("Could not find serviceId in the span so not enriching it with API." + "tenantId: {}, traceId: {}, span: {}", event.getCustomerId(), HexUtils.getHex(trace.getTraceId()), event);
return;
}
Entity apiEntity = null;
try {
apiEntity = getOperationNameBasedEndpointDiscoverer(customerId, serviceId, serviceName).getApiEntity(event);
} catch (Exception e) {
LOGGER.error("Unable to get apiEntity for tenantId {}, serviceId {} and event {}", customerId, serviceId, event, e);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("tenantId: {}, serviceId: {}, span: {}, apiEntity: {}", customerId, serviceId, event, apiEntity);
}
if (apiEntity != null) {
// API Id
addEnrichedAttribute(event, API_ID_ATTR_NAME, AttributeValueCreator.create(apiEntity.getEntityId()));
// API pattern
addEnrichedAttribute(event, API_URL_PATTERN_ATTR_NAME, AttributeValueCreator.create(apiEntity.getEntityName()));
// API name
org.hypertrace.entity.data.service.v1.AttributeValue apiNameValue = apiEntity.getAttributesMap().get(API_NAME_ATTR_NAME);
if (apiNameValue != null) {
addEnrichedAttribute(event, API_NAME_ATTR_NAME, AttributeValueCreator.create(apiNameValue.getValue().getString()));
}
// API Discovery
org.hypertrace.entity.data.service.v1.AttributeValue apiDiscoveryState = apiEntity.getAttributesMap().get(API_DISCOVERY_STATE_ATTR);
if (apiDiscoveryState != null) {
addEnrichedAttribute(event, API_DISCOVERY_STATE_ATTR, AttributeValueCreator.create(apiDiscoveryState.getValue().getString()));
}
}
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.
the class RabbitMqBackendProviderTest method testEventResolution.
@Test
public void testEventResolution() {
String routingKey = "routingkey";
BackendInfo backendInfo = backendEntityEnricher.resolve(getRabbitMqEvent(routingKey), structuredTrace, structuredTraceGraph).get();
Entity entity = backendInfo.getEntity();
Assertions.assertEquals(routingKey, entity.getEntityName());
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("receive"), "BACKEND_DESTINATION", AttributeValueCreator.create("routingkey.QueueName")), attributes);
}
Aggregations