Search in sources :

Example 26 with MutableSpan

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

the class TracingTest method spanHandler_dataChangesVisibleToZipkin.

@Test
public void spanHandler_dataChangesVisibleToZipkin() {
    String serviceNameOverride = "favistar";
    SpanHandler spanHandler = new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            span.localServiceName(serviceNameOverride);
            return true;
        }
    };
    List<zipkin2.Span> zipkinSpans = new ArrayList<>();
    try (Tracing tracing = Tracing.newBuilder().spanReporter(zipkinSpans::add).addSpanHandler(spanHandler).build()) {
        tracing.tracer().newTrace().start().finish();
    }
    assertThat(zipkinSpans.get(0).localServiceName()).isEqualTo(serviceNameOverride);
}
Also used : MutableSpan(brave.handler.MutableSpan) ArrayList(java.util.ArrayList) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) TestSpanHandler(brave.test.TestSpanHandler) FinishedSpanHandler(brave.handler.FinishedSpanHandler) SpanHandler(brave.handler.SpanHandler) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 27 with MutableSpan

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

the class TracingTest method spanHandler_multiple.

@Test
public void spanHandler_multiple() {
    SpanHandler one = new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            return true;
        }
    };
    SpanHandler two = new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            return true;
        }
    };
    try (Tracing tracing = Tracing.newBuilder().addSpanHandler(one).addSpanHandler(two).build()) {
        assertThat((Object) tracing.tracer().pendingSpans).extracting("spanHandler.delegate.handlers").asInstanceOf(InstanceOfAssertFactories.array(SpanHandler[].class)).containsExactly(one, two);
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) TestSpanHandler(brave.test.TestSpanHandler) FinishedSpanHandler(brave.handler.FinishedSpanHandler) SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 28 with MutableSpan

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

the class ITKafkaStreamsTracing method should_create_span_from_stream_input_topic_using_kafka_client_supplier.

@Test
public void should_create_span_from_stream_input_topic_using_kafka_client_supplier() {
    String inputTopic = testName.getMethodName() + "-input";
    StreamsBuilder builder = new StreamsBuilder();
    builder.stream(inputTopic).foreach((k, v) -> {
    });
    Topology topology = builder.build();
    KafkaStreams streams = new KafkaStreams(topology, streamsProperties(), kafkaStreamsTracing.kafkaClientSupplier());
    send(new ProducerRecord<>(inputTopic, TEST_KEY, TEST_VALUE));
    waitForStreamToRun(streams);
    MutableSpan spanInput = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertThat(spanInput.tags()).containsEntry("kafka.topic", inputTopic);
    streams.close();
    streams.cleanUp();
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KafkaStreams(org.apache.kafka.streams.KafkaStreams) MutableSpan(brave.handler.MutableSpan) Topology(org.apache.kafka.streams.Topology) Test(org.junit.Test)

Example 29 with MutableSpan

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

the class ITKafkaStreamsTracing method should_create_span_from_stream_input_topic.

@Test
public void should_create_span_from_stream_input_topic() {
    String inputTopic = testName.getMethodName() + "-input";
    StreamsBuilder builder = new StreamsBuilder();
    builder.stream(inputTopic).foreach((k, v) -> {
    });
    Topology topology = builder.build();
    KafkaStreams streams = buildKafkaStreams(topology);
    send(new ProducerRecord<>(inputTopic, TEST_KEY, TEST_VALUE));
    waitForStreamToRun(streams);
    MutableSpan spanInput = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertThat(spanInput.tags()).containsEntry("kafka.topic", inputTopic);
    streams.close();
    streams.cleanUp();
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KafkaStreams(org.apache.kafka.streams.KafkaStreams) MutableSpan(brave.handler.MutableSpan) Topology(org.apache.kafka.streams.Topology) Test(org.junit.Test)

Example 30 with MutableSpan

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

the class ITKafkaStreamsTracing method should_create_spans_from_stream_with_tracing_foreach.

@Test
public void should_create_spans_from_stream_with_tracing_foreach() {
    String inputTopic = testName.getMethodName() + "-input";
    StreamsBuilder builder = new StreamsBuilder();
    builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String())).process(kafkaStreamsTracing.foreach("foreach-1", (key, value) -> {
        try {
            Thread.sleep(100L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }));
    Topology topology = builder.build();
    KafkaStreams streams = buildKafkaStreams(topology);
    send(new ProducerRecord<>(inputTopic, TEST_KEY, TEST_VALUE));
    waitForStreamToRun(streams);
    MutableSpan spanInput = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertThat(spanInput.tags()).containsEntry("kafka.topic", inputTopic);
    MutableSpan spanProcessor = testSpanHandler.takeLocalSpan();
    assertChildOf(spanProcessor, spanInput);
    streams.close();
    streams.cleanUp();
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) StreamsConfig(org.apache.kafka.streams.StreamsConfig) TEST_KEY(brave.kafka.streams.KafkaStreamsTracingTest.TEST_KEY) Arrays(java.util.Arrays) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ValueTransformerSupplier(org.apache.kafka.streams.kstream.ValueTransformerSupplier) Produced(org.apache.kafka.streams.kstream.Produced) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProcessorSupplier(org.apache.kafka.streams.processor.ProcessorSupplier) ArrayList(java.util.ArrayList) TransformerSupplier(org.apache.kafka.streams.kstream.TransformerSupplier) KafkaJunitRule(com.github.charithe.kafka.KafkaJunitRule) After(org.junit.After) Serdes(org.apache.kafka.common.serialization.Serdes) ValueTransformer(org.apache.kafka.streams.kstream.ValueTransformer) KafkaTracing(brave.kafka.clients.KafkaTracing) ClassRule(org.junit.ClassRule) PRODUCER(brave.Span.Kind.PRODUCER) Consumer(org.apache.kafka.clients.consumer.Consumer) CommonClientConfigs(org.apache.kafka.clients.CommonClientConfigs) TopicPartition(org.apache.kafka.common.TopicPartition) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) Properties(java.util.Properties) Producer(org.apache.kafka.clients.producer.Producer) Consumed(org.apache.kafka.streams.kstream.Consumed) Transformer(org.apache.kafka.streams.kstream.Transformer) KeyValue(org.apache.kafka.streams.KeyValue) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Test(org.junit.Test) MessagingTracing(brave.messaging.MessagingTracing) TEST_VALUE(brave.kafka.streams.KafkaStreamsTracingTest.TEST_VALUE) TraceContext(brave.propagation.TraceContext) ValueTransformerWithKeySupplier(org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier) Assertions.entry(org.assertj.core.api.Assertions.entry) FileNotFoundException(java.io.FileNotFoundException) EphemeralKafkaBroker(com.github.charithe.kafka.EphemeralKafkaBroker) Objects(java.util.Objects) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) List(java.util.List) MutableSpan(brave.handler.MutableSpan) KAFKA_STREAMS_FILTERED_TAG(brave.kafka.streams.KafkaStreamsTags.KAFKA_STREAMS_FILTERED_TAG) ValueTransformerWithKey(org.apache.kafka.streams.kstream.ValueTransformerWithKey) KafkaStreams(org.apache.kafka.streams.KafkaStreams) AbstractProcessor(org.apache.kafka.streams.processor.AbstractProcessor) CONSUMER(brave.Span.Kind.CONSUMER) Topology(org.apache.kafka.streams.Topology) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) KafkaStreams(org.apache.kafka.streams.KafkaStreams) MutableSpan(brave.handler.MutableSpan) Topology(org.apache.kafka.streams.Topology) 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