Search in sources :

Example 1 with Event

use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.

the class TraceStatsEnricher method enrichTrace.

@Override
public void enrichTrace(StructuredTrace trace) {
    ApiTraceGraph apiTraceGraph = ApiTraceGraphBuilder.buildGraph(trace);
    if (apiTraceGraph.getApiNodeList().isEmpty()) {
        return;
    }
    Event firstNodeHeadSpan = apiTraceGraph.getApiNodeList().get(0).getHeadEvent();
    if (firstNodeHeadSpan == null) {
        return;
    }
    addHeadSpanIdTraceAttribute(trace, firstNodeHeadSpan);
    addUniqueApiNodesCountTraceAttribute(apiTraceGraph.getApiNodeList(), trace);
}
Also used : Event(org.hypertrace.core.datamodel.Event) ApiTraceGraph(org.hypertrace.traceenricher.trace.util.ApiTraceGraph)

Example 2 with Event

use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.

the class AbstractBackendEntityEnricher method enrichTrace.

// At trace level, based on the next span to identify if a backend entity is actually a service
// entity.
@Override
public void enrichTrace(StructuredTrace trace) {
    try {
        StructuredTraceGraph structuredTraceGraph = buildGraph(trace);
        trace.getEventList().stream().filter(event -> EnrichedSpanUtils.isExitSpan(event) && SpanAttributeUtils.isLeafSpan(structuredTraceGraph, event) && canResolveBackend(structuredTraceGraph, event)).map(event -> Pair.of(event, resolve(event, trace, structuredTraceGraph))).filter(pair -> pair.getRight().isPresent()).filter(pair -> isValidBackendEntity(trace, pair.getLeft(), pair.getRight().get())).forEach(pair -> decorateWithBackendEntity(pair.getRight().get(), pair.getLeft(), trace));
    } catch (Exception ex) {
        LOGGER.error("An error occurred while enriching backend", ex);
    }
}
Also used : RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) EnrichedSpanUtils(org.hypertrace.traceenricher.enrichedspan.constants.utils.EnrichedSpanUtils) EntityConstants(org.hypertrace.entity.service.constants.EntityConstants) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) AttributeValueCreator(org.hypertrace.core.datamodel.shared.trace.AttributeValueCreator) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) LinkedHashMap(java.util.LinkedHashMap) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) Pair(org.apache.commons.lang3.tuple.Pair) BackendType(org.hypertrace.traceenricher.enrichment.enrichers.BackendType) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) Map(java.util.Map) BackendProvider(org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider) EnrichedSpanConstants(org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants) Entity(org.hypertrace.entity.data.service.v1.Entity) HexUtils(org.hypertrace.core.datamodel.shared.HexUtils) SpanAttributeUtils(org.hypertrace.core.datamodel.shared.SpanAttributeUtils) Backend(org.hypertrace.traceenricher.enrichedspan.constants.v1.Backend) EntityType(org.hypertrace.entity.v1.entitytype.EntityType) Nullable(javax.annotation.Nullable) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Logger(org.slf4j.Logger) SpanSemanticConventionUtils(org.hypertrace.semantic.convention.utils.span.SpanSemanticConventionUtils) Config(com.typesafe.config.Config) AbstractTraceEnricher(org.hypertrace.traceenricher.enrichment.AbstractTraceEnricher) BackendAttribute(org.hypertrace.entity.constants.v1.BackendAttribute) EnricherUtil(org.hypertrace.traceenricher.util.EnricherUtil) Event(org.hypertrace.core.datamodel.Event) EdsClient(org.hypertrace.entity.data.service.client.EdsClient) ClientRegistry(org.hypertrace.traceenricher.enrichment.clients.ClientRegistry) EntityCache(org.hypertrace.traceenricher.enrichment.enrichers.cache.EntityCache) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) EntityAvroConverter(org.hypertrace.traceenricher.util.EntityAvroConverter) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) Builder(org.hypertrace.entity.data.service.v1.Entity.Builder) StructuredTraceGraph(org.hypertrace.core.datamodel.shared.StructuredTraceGraph) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with Event

use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.

the class EnrichedSpanUtilsTest method getResponseSize_httpProtocol_noSize.

@Test
public void getResponseSize_httpProtocol_noSize() {
    Event e = createMockEventWithEnrichedAttribute("PROTOCOL", "HTTP");
    when(e.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(new HashMap<>()).build());
    Optional<Integer> requestSize = EnrichedSpanUtils.getResponseSize(e);
    assertTrue(requestSize.isEmpty());
}
Also used : Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 4 with Event

use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.

the class EnrichedSpanUtilsTest method should_getNullUrl_noHttpFields.

@Test
public void should_getNullUrl_noHttpFields() {
    Event e = mock(Event.class);
    when(e.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(new HashMap<>()).build());
    Optional<String> url = EnrichedSpanUtils.getFullHttpUrl(e);
    assertTrue(url.isEmpty());
}
Also used : Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 5 with Event

use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.

the class EnrichedSpanUtilsTest method createMockEventWithAttribute.

private Event createMockEventWithAttribute(String key, String value) {
    Event e = mock(Event.class);
    when(e.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(Map.of(key, AttributeValue.newBuilder().setValue(value).build())).build());
    when(e.getEnrichedAttributes()).thenReturn(null);
    return e;
}
Also used : Event(org.hypertrace.core.datamodel.Event)

Aggregations

Event (org.hypertrace.core.datamodel.Event)304 Test (org.junit.jupiter.api.Test)257 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)54 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)54 Attributes (org.hypertrace.core.datamodel.Attributes)41 Entity (org.hypertrace.entity.data.service.v1.Entity)27 HashMap (java.util.HashMap)25 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)17 ByteBuffer (java.nio.ByteBuffer)13 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)13 StructuredTraceGraph (org.hypertrace.core.datamodel.shared.StructuredTraceGraph)12 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)10 SemanticConventionTestUtil.buildAttributes (org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes)8 Edge (org.hypertrace.core.datamodel.Edge)7 Entity (org.hypertrace.core.datamodel.Entity)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5