Class KafkaStreamsTracing


  • public final class KafkaStreamsTracing
    extends java.lang.Object
    Use this class to decorate Kafka Stream Topologies and enable Tracing.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static KafkaStreamsTracing create​(brave.Tracing tracing)  
      <K,​V>
      org.apache.kafka.streams.processor.ProcessorSupplier<K,​V>
      foreach​(java.lang.String spanName, org.apache.kafka.streams.kstream.ForeachAction<K,​V> action)
      Create a foreach processor, similar to KStream.foreach(ForeachAction), where its action will be recorded in a new span with the indicated name.
      org.apache.kafka.streams.KafkaStreams kafkaStreams​(org.apache.kafka.streams.Topology topology, java.util.Properties streamsConfig)
      Creates a KafkaStreams instance with a tracing-enabled KafkaClientSupplier.
      <K,​V,​KR,​VR>
      org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​org.apache.kafka.streams.KeyValue<KR,​VR>>
      map​(java.lang.String spanName, org.apache.kafka.streams.kstream.KeyValueMapper<K,​V,​org.apache.kafka.streams.KeyValue<KR,​VR>> mapper)
      Create a map transformer, similar to KStream.map(KeyValueMapper), where its mapper action will be recorded in a new span with the indicated name.
      <V,​VR>
      org.apache.kafka.streams.kstream.ValueTransformerSupplier<V,​VR>
      mapValues​(java.lang.String spanName, org.apache.kafka.streams.kstream.ValueMapper<V,​VR> mapper)
      Create a peek transformer, similar to KStream.mapValues(ValueMapper), where its mapper action will be recorded in a new span with the indicated name.
      <K,​V,​VR>
      org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier<K,​V,​VR>
      mapValues​(java.lang.String spanName, org.apache.kafka.streams.kstream.ValueMapperWithKey<K,​V,​VR> mapper)
      Create a peek transformer, similar to KStream.mapValues(ValueMapperWithKey), where its mapper action will be recorded in a new span with the indicated name.
      <K,​V>
      org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​org.apache.kafka.streams.KeyValue<K,​V>>
      mark​(java.lang.String spanName)
      Create a mark transformer, similar to KStream.peek(ForeachAction), but no action is executed.
      <K,​V>
      org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​org.apache.kafka.streams.KeyValue<K,​V>>
      peek​(java.lang.String spanName, org.apache.kafka.streams.kstream.ForeachAction<K,​V> action)
      Create a peek transformer, similar to KStream.peek(ForeachAction), where its action will be recorded in a new span with the indicated name.
      <K,​V>
      org.apache.kafka.streams.processor.ProcessorSupplier<K,​V>
      processor​(java.lang.String spanName, org.apache.kafka.streams.processor.Processor<K,​V> processor)
      Create a tracing-decorated ProcessorSupplier
      <K,​V,​R>
      org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​R>
      transformer​(java.lang.String spanName, org.apache.kafka.streams.kstream.Transformer<K,​V,​R> transformer)
      Create a tracing-decorated TransformerSupplier
      <V,​VR>
      org.apache.kafka.streams.kstream.ValueTransformerSupplier<V,​VR>
      valueTransformer​(java.lang.String spanName, org.apache.kafka.streams.kstream.ValueTransformer<V,​VR> valueTransformer)
      Create a tracing-decorated ValueTransformerSupplier
      <K,​V,​VR>
      org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier<K,​V,​VR>
      valueTransformerWithKey​(java.lang.String spanName, org.apache.kafka.streams.kstream.ValueTransformerWithKey<K,​V,​VR> valueTransformerWithKey)
      Create a tracing-decorated ValueTransformerWithKeySupplier
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • kafkaStreams

        public org.apache.kafka.streams.KafkaStreams kafkaStreams​(org.apache.kafka.streams.Topology topology,
                                                                  java.util.Properties streamsConfig)
        Creates a KafkaStreams instance with a tracing-enabled KafkaClientSupplier. All Topology Sources and Sinks (including internal Topics) will create Spans on records processed (i.e. send or consumed). Use this instead of KafkaStreams constructor.

        Simple example:

        
         // KafkaStreams with tracing-enabled KafkaClientSupplier
         KafkaStreams kafkaStreams = kafkaStreamsTracing.kafkaStreams(topology, streamsConfig);
         
        See Also:
        TracingKafkaClientSupplier
      • processor

        public <K,​V> org.apache.kafka.streams.processor.ProcessorSupplier<K,​V> processor​(java.lang.String spanName,
                                                                                                     org.apache.kafka.streams.processor.Processor<K,​V> processor)
        Create a tracing-decorated ProcessorSupplier

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .process(kafkaStreamsTracing.processor("my-processor", myProcessor);
         
        See Also:
        TracingKafkaClientSupplier
      • transformer

        public <K,​V,​R> org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​R> transformer​(java.lang.String spanName,
                                                                                                                       org.apache.kafka.streams.kstream.Transformer<K,​V,​R> transformer)
        Create a tracing-decorated TransformerSupplier

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transform(kafkaStreamsTracing.transformer("my-transformer", myTransformer)
                .to(outputTopic);
         
      • valueTransformer

        public <V,​VR> org.apache.kafka.streams.kstream.ValueTransformerSupplier<V,​VR> valueTransformer​(java.lang.String spanName,
                                                                                                                   org.apache.kafka.streams.kstream.ValueTransformer<V,​VR> valueTransformer)
        Create a tracing-decorated ValueTransformerSupplier

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transformValues(kafkaStreamsTracing.valueTransformer("my-transformer", myTransformer)
                .to(outputTopic);
         
      • valueTransformerWithKey

        public <K,​V,​VR> org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier<K,​V,​VR> valueTransformerWithKey​(java.lang.String spanName,
                                                                                                                                                 org.apache.kafka.streams.kstream.ValueTransformerWithKey<K,​V,​VR> valueTransformerWithKey)
        Create a tracing-decorated ValueTransformerWithKeySupplier

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transformValues(kafkaStreamsTracing.valueTransformerWithKey("my-transformer", myTransformer)
                .to(outputTopic);
         
      • foreach

        public <K,​V> org.apache.kafka.streams.processor.ProcessorSupplier<K,​V> foreach​(java.lang.String spanName,
                                                                                                   org.apache.kafka.streams.kstream.ForeachAction<K,​V> action)
        Create a foreach processor, similar to KStream.foreach(ForeachAction), where its action will be recorded in a new span with the indicated name.

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .process(kafkaStreamsTracing.foreach("myForeach", (k, v) -> ...);
         
      • peek

        public <K,​V> org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​org.apache.kafka.streams.KeyValue<K,​V>> peek​(java.lang.String spanName,
                                                                                                                                                   org.apache.kafka.streams.kstream.ForeachAction<K,​V> action)
        Create a peek transformer, similar to KStream.peek(ForeachAction), where its action will be recorded in a new span with the indicated name.

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transform(kafkaStreamsTracing.peek("myPeek", (k, v) -> ...)
                .to(outputTopic);
         
      • mark

        public <K,​V> org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​org.apache.kafka.streams.KeyValue<K,​V>> mark​(java.lang.String spanName)
        Create a mark transformer, similar to KStream.peek(ForeachAction), but no action is executed. Instead, only a span is created to represent an event as part of the stream process. A common scenario for this transformer is to mark the beginning and end of a step (or set of steps) in a stream process.

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transform(kafkaStreamsTracing.mark("beginning-complex-map")
                .map(complexTransformation1)
                .filter(predicate)
                .map(complexTransformation2)
                .transform(kafkaStreamsTracing.mark("end-complex-transformation")
                .to(outputTopic);
         
      • map

        public <K,​V,​KR,​VR> org.apache.kafka.streams.kstream.TransformerSupplier<K,​V,​org.apache.kafka.streams.KeyValue<KR,​VR>> map​(java.lang.String spanName,
                                                                                                                                                                      org.apache.kafka.streams.kstream.KeyValueMapper<K,​V,​org.apache.kafka.streams.KeyValue<KR,​VR>> mapper)
        Create a map transformer, similar to KStream.map(KeyValueMapper), where its mapper action will be recorded in a new span with the indicated name.

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transform(kafkaStreamsTracing.map("myMap", (k, v) -> ...)
                .to(outputTopic);
         
      • mapValues

        public <K,​V,​VR> org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier<K,​V,​VR> mapValues​(java.lang.String spanName,
                                                                                                                                   org.apache.kafka.streams.kstream.ValueMapperWithKey<K,​V,​VR> mapper)
        Create a peek transformer, similar to KStream.mapValues(ValueMapperWithKey), where its mapper action will be recorded in a new span with the indicated name.

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transform(kafkaStreamsTracing.mapValues("myMapValues", (k, v) -> ...)
                .to(outputTopic);
         
      • mapValues

        public <V,​VR> org.apache.kafka.streams.kstream.ValueTransformerSupplier<V,​VR> mapValues​(java.lang.String spanName,
                                                                                                            org.apache.kafka.streams.kstream.ValueMapper<V,​VR> mapper)
        Create a peek transformer, similar to KStream.mapValues(ValueMapper), where its mapper action will be recorded in a new span with the indicated name.

        Simple example using Kafka Streams DSL:

        
         StreamsBuilder builder = new StreamsBuilder();
         builder.stream(inputTopic)
                .transform(kafkaStreamsTracing.mapValues("myMapValues", v -> ...)
                .to(outputTopic);