Search in sources :

Example 11 with StructuredTrace

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

the class TraceEmitPunctuator method punctuate.

/**
 * @param timestamp correspond to current system time
 */
@Override
public void punctuate(long timestamp) {
    Instant startTime = Instant.now();
    // always cancel the punctuator else it will get re-scheduled automatically
    cancellable.cancel();
    TraceState traceState = traceStateStore.get(key);
    if (null == traceState || null == traceState.getSpanIds() || traceState.getSpanIds().isEmpty()) {
        /*
       todo - debug why this happens .
       Typically seen when punctuators are created via {@link RawSpansGroupingTransformer.restorePunctuators}
      */
        logger.warn("TraceState for tenant_id=[{}], trace_id=[{}] is missing.", key.getTenantId(), HexUtils.getHex(key.getTraceId()));
        return;
    }
    long emitTs = traceState.getEmitTs();
    if (emitTs <= timestamp) {
        // we can emit this trace so just delete the entry for this 'key'
        // Implies that no new spans for the trace have arrived within the last
        // 'groupingWindowTimeoutMs' interval
        // so the trace can be finalized and emitted
        traceStateStore.delete(key);
        ByteBuffer traceId = traceState.getTraceId();
        String tenantId = traceState.getTenantId();
        List<RawSpan> rawSpanList = new ArrayList<>();
        Set<ByteBuffer> spanIds = new HashSet<>(traceState.getSpanIds());
        spanIds.forEach(v -> {
            SpanIdentity spanIdentity = new SpanIdentity(tenantId, traceId, v);
            RawSpan rawSpan = spanStore.delete(spanIdentity);
            // ideally this shouldn't happen
            if (rawSpan != null) {
                rawSpanList.add(rawSpan);
            }
        });
        if (traceState.getSpanIds().size() != spanIds.size()) {
            tenantToTraceWithDuplicateSpansCounter.computeIfAbsent(tenantId, k -> PlatformMetricsRegistry.registerCounter(TRACE_WITH_DUPLICATE_SPANS, Map.of("tenantId", k))).increment();
            if (logger.isDebugEnabled()) {
                logger.debug("Duplicate spanIds: [{}], unique spanIds count: [{}] for tenant: [{}] trace: [{}]", traceState.getSpanIds().size(), spanIds.size(), tenantId, HexUtils.getHex(traceId));
            }
        }
        recordSpansPerTrace(rawSpanList.size(), List.of(Tag.of("tenant_id", tenantId)));
        Timestamps timestamps = trackEndToEndLatencyTimestamps(timestamp, traceState.getTraceStartTimestamp());
        StructuredTrace trace = StructuredTraceBuilder.buildStructuredTraceFromRawSpans(rawSpanList, traceId, tenantId, timestamps);
        if (logger.isDebugEnabled()) {
            logger.debug("Emit tenant_id=[{}], trace_id=[{}], spans_count=[{}]", tenantId, HexUtils.getHex(traceId), rawSpanList.size());
        }
        // report entries in spanStore
        if (spanStoreCountRateLimiter.tryAcquire()) {
            tenantToSpanStoreCountCounter.computeIfAbsent(tenantId, k -> PlatformMetricsRegistry.registerCounter(SPAN_STORE_COUNT, Map.of("tenantId", k))).increment(spanStore.approximateNumEntries() * 1.0);
        }
        // report count of spanIds per trace
        tenantToSpanPerTraceCounter.computeIfAbsent(tenantId, k -> PlatformMetricsRegistry.registerCounter(SPANS_PER_TRACE, Map.of("tenantId", k))).increment(spanIds.size() * 1.0);
        // report trace emitted count
        tenantToTraceEmittedCounter.computeIfAbsent(tenantId, k -> PlatformMetricsRegistry.registerCounter(TRACES_EMITTER_COUNTER, Map.of("tenantId", k))).increment();
        // report punctuate latency
        tenantToPunctuateLatencyTimer.computeIfAbsent(tenantId, k -> PlatformMetricsRegistry.registerTimer(PUNCTUATE_LATENCY_TIMER, Map.of("tenantId", k))).record(Duration.between(startTime, Instant.now()).toMillis(), TimeUnit.MILLISECONDS);
        context.forward(null, trace, outputTopicProducer);
    } else {
        // so the session inactivity window is extended from the last timestamp
        if (logger.isDebugEnabled()) {
            logger.debug("Re-scheduling emit trigger for tenant_id=[{}], trace_id=[{}] to [{}]", key.getTenantId(), HexUtils.getHex(key.getTraceId()), Instant.ofEpochMilli(emitTs + groupingWindowTimeoutMs));
        }
        long newEmitTs = emitTs + groupingWindowTimeoutMs;
        // if current timestamp is ahead of newEmitTs then just add a grace of 100ms and fire it
        long duration = Math.max(100, newEmitTs - timestamp);
        cancellable = context.schedule(Duration.ofMillis(duration), PunctuationType.WALL_CLOCK_TIME, this);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) TraceState(org.hypertrace.core.spannormalizer.TraceState) HashMap(java.util.HashMap) SPANS_PER_TRACE_METRIC(org.hypertrace.core.rawspansgrouper.RawSpanGrouperConstants.SPANS_PER_TRACE_METRIC) RateLimiter(com.google.common.util.concurrent.RateLimiter) ByteBuffer(java.nio.ByteBuffer) To(org.apache.kafka.streams.processor.To) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) PlatformMetricsRegistry(org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry) Timer(io.micrometer.core.instrument.Timer) Duration(java.time.Duration) Map(java.util.Map) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) PunctuationType(org.apache.kafka.streams.processor.PunctuationType) Timestamps(org.hypertrace.core.datamodel.Timestamps) HexUtils(org.hypertrace.core.datamodel.shared.HexUtils) TraceIdentity(org.hypertrace.core.spannormalizer.TraceIdentity) SpanIdentity(org.hypertrace.core.spannormalizer.SpanIdentity) Counter(io.micrometer.core.instrument.Counter) RawSpan(org.hypertrace.core.datamodel.RawSpan) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Tag(io.micrometer.core.instrument.Tag) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Punctuator(org.apache.kafka.streams.processor.Punctuator) Set(java.util.Set) StructuredTraceBuilder(org.hypertrace.core.datamodel.shared.trace.StructuredTraceBuilder) Instant(java.time.Instant) DataflowMetricUtils(org.hypertrace.core.datamodel.shared.DataflowMetricUtils) TimeUnit(java.util.concurrent.TimeUnit) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) List(java.util.List) Cancellable(org.apache.kafka.streams.processor.Cancellable) DistributionSummary(io.micrometer.core.instrument.DistributionSummary) TRACE_CREATION_TIME(org.hypertrace.core.rawspansgrouper.RawSpanGrouperConstants.TRACE_CREATION_TIME) TimestampRecord(org.hypertrace.core.datamodel.TimestampRecord) TraceState(org.hypertrace.core.spannormalizer.TraceState) Instant(java.time.Instant) ArrayList(java.util.ArrayList) RawSpan(org.hypertrace.core.datamodel.RawSpan) ByteBuffer(java.nio.ByteBuffer) SpanIdentity(org.hypertrace.core.spannormalizer.SpanIdentity) Timestamps(org.hypertrace.core.datamodel.Timestamps) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) HashSet(java.util.HashSet)

Example 12 with StructuredTrace

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

the class RawSpansGrouperTest method whenRawSpansAreReceivedWithInactivityExpectTraceToBeOutput.

@Test
@SetEnvironmentVariable(key = "SERVICE_NAME", value = "raw-spans-grouper")
public void whenRawSpansAreReceivedWithInactivityExpectTraceToBeOutput(@TempDir Path tempDir) {
    File file = tempDir.resolve("state").toFile();
    RawSpansGrouper underTest = new RawSpansGrouper(ConfigClientFactory.getClient());
    Config config = ConfigFactory.parseURL(getClass().getClassLoader().getResource("configs/raw-spans-grouper/application.conf"));
    Map<String, Object> baseProps = underTest.getBaseStreamsConfig();
    Map<String, Object> streamsProps = underTest.getStreamsConfig(config);
    baseProps.forEach(streamsProps::put);
    Map<String, Object> mergedProps = streamsProps;
    mergedProps.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, SpecificAvroSerde.class);
    mergedProps.put(RawSpanGrouperConstants.RAW_SPANS_GROUPER_JOB_CONFIG, config);
    mergedProps.put(StreamsConfig.STATE_DIR_CONFIG, file.getAbsolutePath());
    StreamsBuilder streamsBuilder = underTest.buildTopology(mergedProps, new StreamsBuilder(), new HashMap<>());
    Properties props = new Properties();
    mergedProps.forEach(props::put);
    Serde defaultValueSerde = new StreamsConfig(mergedProps).defaultValueSerde();
    Serde<TraceIdentity> traceIdentitySerde = new StreamsConfig(mergedProps).defaultKeySerde();
    TopologyTestDriver td = new TopologyTestDriver(streamsBuilder.build(), props);
    TestInputTopic<TraceIdentity, RawSpan> inputTopic = td.createInputTopic(config.getString(RawSpanGrouperConstants.INPUT_TOPIC_CONFIG_KEY), traceIdentitySerde.serializer(), defaultValueSerde.serializer());
    TestOutputTopic outputTopic = td.createOutputTopic(config.getString(RawSpanGrouperConstants.OUTPUT_TOPIC_CONFIG_KEY), Serdes.String().deserializer(), defaultValueSerde.deserializer());
    String tenantId = "tenant1";
    // create spans for trace-1 of tenant1
    RawSpan span1 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-1".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-1", "tenant1")).build();
    RawSpan span2 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-1".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-2", "tenant1")).build();
    RawSpan span3 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-1".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-3", "tenant1")).build();
    // create spans for trace-2 of tenant1
    RawSpan span4 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-2".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-4", "tenant1")).build();
    RawSpan span5 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-2".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-5", "tenant1")).build();
    // create spans for trace-3 of tenant1
    RawSpan span6 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-3".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-6", "tenant1")).build();
    RawSpan span7 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-3".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-7", "tenant1")).build();
    RawSpan span8 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-3".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-8", "tenant1")).build();
    RawSpan span9 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-3".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-9", "tenant1")).build();
    RawSpan span10 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-3".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-10", "tenant1")).build();
    RawSpan span11 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-3".getBytes())).setCustomerId("tenant1").setEvent(createEvent("event-11", "tenant1")).build();
    // create 8 spans for tenant-2 for trace-4
    String tenant2 = "tenant2";
    RawSpan span12 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-12", tenant2)).build();
    RawSpan span13 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-13", tenant2)).build();
    RawSpan span14 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-14", tenant2)).build();
    RawSpan span15 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-15", tenant2)).build();
    RawSpan span16 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-16", tenant2)).build();
    RawSpan span17 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-17", tenant2)).build();
    RawSpan span18 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-18", tenant2)).build();
    RawSpan span19 = RawSpan.newBuilder().setTraceId(ByteBuffer.wrap("trace-4".getBytes())).setCustomerId(tenant2).setEvent(createEvent("event-19", tenant2)).build();
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-1"), span1);
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-2"), span4);
    td.advanceWallClockTime(Duration.ofSeconds(1));
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-1"), span2);
    // select a value < 30s (groupingWindowTimeoutInMs)
    // this shouldn't trigger a punctuate call
    td.advanceWallClockTime(Duration.ofMillis(200));
    assertTrue(outputTopic.isEmpty());
    // the next advance should trigger a punctuate call and emit a trace with 2 spans
    td.advanceWallClockTime(Duration.ofSeconds(32));
    // trace1 should have 2 span span1, span2
    StructuredTrace trace = (StructuredTrace) outputTopic.readValue();
    assertEquals(2, trace.getEventList().size());
    Set<String> traceEventIds = trace.getEventList().stream().map(id -> new String(id.getEventId().array())).collect(Collectors.toSet());
    assertTrue(traceEventIds.contains("event-1"));
    assertTrue(traceEventIds.contains("event-2"));
    // trace2 should have 1 span span3
    trace = (StructuredTrace) outputTopic.readValue();
    assertEquals(1, trace.getEventList().size());
    assertEquals("event-4", new String(trace.getEventList().get(0).getEventId().array()));
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-1"), span3);
    td.advanceWallClockTime(Duration.ofSeconds(45));
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-2"), span5);
    // the next advance should trigger a punctuate call and emit a trace with 2 spans
    td.advanceWallClockTime(Duration.ofSeconds(35));
    // trace1 should have 1 span i.e. span3
    trace = (StructuredTrace) outputTopic.readValue();
    assertEquals(1, trace.getEventList().size());
    assertEquals("event-3", new String(trace.getEventList().get(0).getEventId().array()));
    // trace2 should have 1 span i.e. span4
    trace = (StructuredTrace) outputTopic.readValue();
    assertEquals(1, trace.getEventList().size());
    assertEquals("event-5", new String(trace.getEventList().get(0).getEventId().array()));
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-3"), span6);
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-3"), span7);
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-3"), span8);
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-3"), span9);
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-3"), span10);
    inputTopic.pipeInput(createTraceIdentity(tenantId, "trace-3"), span11);
    td.advanceWallClockTime(Duration.ofSeconds(35));
    // trace should be truncated with 5 spans
    trace = (StructuredTrace) outputTopic.readValue();
    assertEquals(5, trace.getEventList().size());
    // input 8 spans of trace-4 for tenant2, as there is global upper limit apply, it will emit only
    // 6
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span12);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span13);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span14);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span15);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span16);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span17);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span18);
    inputTopic.pipeInput(createTraceIdentity(tenant2, "trace-4"), span19);
    td.advanceWallClockTime(Duration.ofSeconds(35));
    trace = (StructuredTrace) outputTopic.readValue();
    assertEquals(6, trace.getEventList().size());
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) SpecificAvroSerde(io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde) StreamsConfig(org.apache.kafka.streams.StreamsConfig) SetEnvironmentVariable(org.junitpioneer.jupiter.SetEnvironmentVariable) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) Serde(org.apache.kafka.common.serialization.Serde) Duration(java.time.Duration) Map(java.util.Map) ConfigFactory(com.typesafe.config.ConfigFactory) Serdes(org.apache.kafka.common.serialization.Serdes) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TraceIdentity(org.hypertrace.core.spannormalizer.TraceIdentity) Path(java.nio.file.Path) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) RawSpan(org.hypertrace.core.datamodel.RawSpan) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) ConfigClientFactory(org.hypertrace.core.serviceframework.config.ConfigClientFactory) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) Properties(java.util.Properties) TestOutputTopic(org.apache.kafka.streams.TestOutputTopic) Config(com.typesafe.config.Config) Event(org.hypertrace.core.datamodel.Event) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) SpecificAvroSerde(io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde) Test(org.junit.jupiter.api.Test) TempDir(org.junit.jupiter.api.io.TempDir) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestInputTopic(org.apache.kafka.streams.TestInputTopic) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Config(com.typesafe.config.Config) TraceIdentity(org.hypertrace.core.spannormalizer.TraceIdentity) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) RawSpan(org.hypertrace.core.datamodel.RawSpan) Properties(java.util.Properties) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) File(java.io.File) StreamsConfig(org.apache.kafka.streams.StreamsConfig) TestOutputTopic(org.apache.kafka.streams.TestOutputTopic) SetEnvironmentVariable(org.junitpioneer.jupiter.SetEnvironmentVariable) Test(org.junit.jupiter.api.Test)

Example 13 with StructuredTrace

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

the class BackendEntityViewGeneratorTest method testBackendEntityViewGenerator_HotrodTrace.

@Test
public void testBackendEntityViewGenerator_HotrodTrace() throws IOException {
    StructuredTrace trace = TestUtilities.getSampleHotRodTrace();
    BackendEntityViewGenerator backendEntityViewGenerator = new BackendEntityViewGenerator();
    List<BackendEntityView> backendEntityViews = backendEntityViewGenerator.process(trace);
    List<Event> computedBackendEvents = getEventsWithBackendEntity(trace);
    assertEntity(backendEntityViews, computedBackendEvents);
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) BackendEntityView(org.hypertrace.viewgenerator.api.BackendEntityView) Test(org.junit.jupiter.api.Test)

Example 14 with StructuredTrace

use of org.hypertrace.core.datamodel.StructuredTrace 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)

Example 15 with StructuredTrace

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

the class SpanEventViewGeneratorTest method testSpanEventViewGen_HotrodTrace.

@Test
public void testSpanEventViewGen_HotrodTrace() throws IOException {
    URL resource = Thread.currentThread().getContextClassLoader().getResource("StructuredTrace-Hotrod.avro");
    SpecificDatumReader<StructuredTrace> datumReader = new SpecificDatumReader<>(StructuredTrace.getClassSchema());
    DataFileReader<StructuredTrace> dfrStructuredTrace = new DataFileReader<>(new File(resource.getPath()), datumReader);
    StructuredTrace trace = dfrStructuredTrace.next();
    dfrStructuredTrace.close();
    TraceState traceState = new TraceState(trace);
    verifyGetExitSpanToApiEntrySpan_HotrodTrace(trace, traceState);
    SpanEventViewGenerator spanEventViewGenerator = new SpanEventViewGenerator();
    List<SpanEventView> spanEventViews = spanEventViewGenerator.process(trace);
    assertEquals(50, spanEventViews.size());
}
Also used : TraceState(org.hypertrace.viewgenerator.generators.ViewGeneratorState.TraceState) DataFileReader(org.apache.avro.file.DataFileReader) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) SpanEventView(org.hypertrace.viewgenerator.api.SpanEventView) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) File(java.io.File) URL(java.net.URL) HTTP_URL(org.hypertrace.core.span.constants.v1.Http.HTTP_URL) Test(org.junit.jupiter.api.Test)

Aggregations

StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)79 Test (org.junit.jupiter.api.Test)66 Event (org.hypertrace.core.datamodel.Event)47 HashMap (java.util.HashMap)15 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)15 Config (com.typesafe.config.Config)7 ByteBuffer (java.nio.ByteBuffer)7 Map (java.util.Map)7 Edge (org.hypertrace.core.datamodel.Edge)7 File (java.io.File)6 List (java.util.List)6 Entity (org.hypertrace.entity.data.service.v1.Entity)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)5 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)5 RawSpan (org.hypertrace.core.datamodel.RawSpan)5 HexUtils (org.hypertrace.core.datamodel.shared.HexUtils)5 Counter (io.micrometer.core.instrument.Counter)4 Duration (java.time.Duration)4 Instant (java.time.Instant)4