use of org.hypertrace.core.datamodel.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.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class ByPassPredicate method test.
@Override
public boolean test(TraceIdentity traceIdentity, RawSpan rawSpan) {
AttributeValue defaultAttributeValue = AttributeValue.newBuilder().setValue("false").build();
AttributeValue attributeValue = bypassKey != null ? rawSpan.getEvent().getAttributes().getAttributeMap().getOrDefault(bypassKey, defaultAttributeValue) : defaultAttributeValue;
return Boolean.parseBoolean(attributeValue.getValue());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class JaegerSpanNormalizerTest method testConvertToJsonString.
@Test
public void testConvertToJsonString() throws IOException {
AttributeValue attributeValue = AttributeValue.newBuilder().setValue("test-val").build();
Assertions.assertEquals("{\"value\":{\"string\":\"test-val\"},\"binary_value\":null,\"value_list\":null,\"value_map\":null}", JaegerSpanNormalizer.convertToJsonString(attributeValue, AttributeValue.getClassSchema()));
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class HttpSemanticConventionUtils method getHttpSchemeFromRawAttributes.
private static Optional<String> getHttpSchemeFromRawAttributes(Map<String, AttributeValue> attributeValueMap) {
// dealing with the Forwarded header separately as it may have
// more info than just the protocol
AttributeValue httpRequestForwardedAttributeValue = attributeValueMap.get(HTTP_REQUEST_FORWARDED_ATTRIBUTE);
if (httpRequestForwardedAttributeValue != null && !StringUtils.isEmpty(httpRequestForwardedAttributeValue.getValue())) {
String schemeValue = httpRequestForwardedAttributeValue.getValue();
Optional<String> optionalExtractedProtoValue = getProtocolFromForwarded(schemeValue);
if (optionalExtractedProtoValue.isPresent()) {
return optionalExtractedProtoValue;
}
}
for (String scheme : SCHEME_ATTRIBUTES) {
if (attributeValueMap.get(scheme) != null && !StringUtils.isEmpty(attributeValueMap.get(scheme).getValue())) {
return Optional.of(attributeValueMap.get(scheme).getValue());
}
}
return Optional.empty();
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class SpanEventViewGeneratorTest method testApiTraceErrorSpanCount.
@Test
public void testApiTraceErrorSpanCount() {
StructuredTrace.Builder traceBuilder = StructuredTrace.newBuilder();
traceBuilder.setCustomerId("customer1").setTraceId(ByteBuffer.wrap("sample-trace-id".getBytes())).setEntityList(Collections.singletonList(Entity.newBuilder().setCustomerId("customer1").setEntityId("sample-entity-id").setEntityName("sample-entity-name").setEntityType("SERVICE").build())).setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(Maps.newHashMap())).build())).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setEntityEdgeList(new ArrayList<>()).setEventEdgeList(new ArrayList<>()).setEntityEventEdgeList(new ArrayList<>()).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis());
StructuredTrace trace = traceBuilder.build();
SpanEventViewGenerator spanEventViewGenerator = new SpanEventViewGenerator();
List<SpanEventView> list = spanEventViewGenerator.process(trace);
assertEquals(0, list.get(0).getApiTraceErrorSpanCount());
Map<String, AttributeValue> spanAttributes = new HashMap<>();
spanAttributes.put(EnrichedSpanConstants.API_TRACE_ERROR_SPAN_COUNT_ATTRIBUTE, AttributeValue.newBuilder().setValue("5").build());
traceBuilder.setEventList(Collections.singletonList(Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("sample-span-id".getBytes())).setEventName("sample-span-name").setEntityIdList(Collections.singletonList("sample-entity-id")).setStartTimeMillis(System.currentTimeMillis()).setEndTimeMillis(System.currentTimeMillis()).setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()).setAttributesBuilder(Attributes.newBuilder().setAttributeMap(new HashMap<>())).setEnrichedAttributesBuilder(Attributes.newBuilder().setAttributeMap(spanAttributes)).build())).build();
trace = traceBuilder.build();
spanEventViewGenerator = new SpanEventViewGenerator();
list = spanEventViewGenerator.process(trace);
assertEquals(5, list.get(0).getApiTraceErrorSpanCount());
}
Aggregations