Search in sources :

Example 6 with AttributeValue

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()));
        }
    }
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue)

Example 7 with AttributeValue

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());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue)

Example 8 with AttributeValue

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()));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Test(org.junit.jupiter.api.Test)

Example 9 with AttributeValue

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();
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue)

Example 10 with AttributeValue

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());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1