Search in sources :

Example 41 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ITKafkaTracing method continues_a_trace_when_only_trace_id_propagated.

@Test
public void continues_a_trace_when_only_trace_id_propagated() {
    consumerTracing = KafkaTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).clearSpanHandlers().addSpanHandler(consumerSpanHandler).propagationFactory(new TraceIdOnlyPropagation()).build());
    producerTracing = KafkaTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).clearSpanHandlers().addSpanHandler(producerSpanHandler).propagationFactory(new TraceIdOnlyPropagation()).build());
    producer = createTracingProducer();
    consumer = createTracingConsumer();
    send(new ProducerRecord<>(testName.getMethodName(), TEST_KEY, TEST_VALUE));
    // intentionally using deprecated method as we are checking the same class in an invoker test
    // under src/it. If we want to explicitly tests the Duration arg, we will have to subclass.
    ConsumerRecords<String, String> records = consumer.poll(10_000L);
    assertThat(records).hasSize(1);
    MutableSpan producerSpan = takeProducerSpan();
    MutableSpan consumerSpan = takeConsumerSpan();
    assertThat(producerSpan.traceId()).isEqualTo(consumerSpan.traceId());
    for (ConsumerRecord<String, String> record : records) {
        TraceContext forProcessor = consumerTracing.nextSpan(record).context();
        assertThat(forProcessor.traceIdString()).isEqualTo(consumerSpan.traceId());
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 42 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ITMongoDBTracing method makesChildOfCurrentSpan.

@Test
public void makesChildOfCurrentSpan() {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        executeFind(COLLECTION_NAME);
    }
    MutableSpan clientSpan = testSpanHandler.takeRemoteSpan(CLIENT);
    assertChildOf(clientSpan, parent);
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 43 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TracingConsumerTest method should_call_wrapped_poll_and_close_spans.

@Test
public void should_call_wrapped_poll_and_close_spans() {
    consumer.addRecord(consumerRecord);
    Consumer<String, String> tracingConsumer = kafkaTracing.consumer(consumer);
    tracingConsumer.poll(10);
    // offset changed
    assertThat(consumer.position(topicPartition)).isEqualTo(2L);
    MutableSpan consumerSpan = spans.get(0);
    assertThat(consumerSpan.kind()).isEqualTo(CONSUMER);
    assertThat(consumerSpan.name()).isEqualTo("poll");
    assertThat(consumerSpan.tags()).containsOnly(entry("kafka.topic", "myTopic"));
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 44 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TracingConsumerTest method should_add_new_trace_headers_if_b3_missing.

@Test
public void should_add_new_trace_headers_if_b3_missing() {
    consumer.addRecord(consumerRecord);
    Consumer<String, String> tracingConsumer = kafkaTracing.consumer(consumer);
    ConsumerRecords<String, String> poll = tracingConsumer.poll(10);
    assertThat(poll).extracting(ConsumerRecord::headers).flatExtracting(KafkaTest::lastHeaders).extracting(Map.Entry::getKey).containsOnly("b3");
    MutableSpan consumerSpan = spans.get(0);
    assertThat(consumerSpan.kind()).isEqualTo(CONSUMER);
    assertThat(consumerSpan.parentId()).isNull();
}
Also used : MutableSpan(brave.handler.MutableSpan) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 45 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TracingProducerTest method should_add_b3_headers_when_other_headers_exist.

@Test
public void should_add_b3_headers_when_other_headers_exist() {
    ProducerRecord<Object, String> record = new ProducerRecord<>(TEST_TOPIC, TEST_KEY, TEST_VALUE);
    record.headers().add("tx-id", "1".getBytes());
    tracingProducer.send(record);
    mockProducer.completeNext();
    MutableSpan producerSpan = spans.get(0);
    assertThat(producerSpan.kind()).isEqualTo(PRODUCER);
    assertThat(lastHeaders(mockProducer)).containsEntry("tx-id", "1").containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Test(org.junit.Test)

Aggregations

MutableSpan (brave.handler.MutableSpan)141 Test (org.junit.Test)107 TraceContext (brave.propagation.TraceContext)36 KafkaStreams (org.apache.kafka.streams.KafkaStreams)28 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)28 Topology (org.apache.kafka.streams.Topology)28 Scope (brave.propagation.CurrentTraceContext.Scope)14 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 KeyValue (org.apache.kafka.streams.KeyValue)9 ArrayList (java.util.ArrayList)8 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)8 MessagingTracing (brave.messaging.MessagingTracing)7 FileNotFoundException (java.io.FileNotFoundException)7 Arrays (java.util.Arrays)7 List (java.util.List)7 CONSUMER (brave.Span.Kind.CONSUMER)6 PRODUCER (brave.Span.Kind.PRODUCER)6 SpanHandler (brave.handler.SpanHandler)6 KafkaTracing (brave.kafka.clients.KafkaTracing)6 KAFKA_STREAMS_FILTERED_TAG (brave.kafka.streams.KafkaStreamsTags.KAFKA_STREAMS_FILTERED_TAG)6