use of brave.handler.MutableSpan in project brave by openzipkin.
the class ITKafkaStreamsTracing method should_create_spans_from_stream_with_tracing_filter_predicate_true.
@Test
public void should_create_spans_from_stream_with_tracing_filter_predicate_true() {
String inputTopic = testName.getMethodName() + "-input";
String outputTopic = testName.getMethodName() + "-output";
StreamsBuilder builder = new StreamsBuilder();
builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String())).transform(kafkaStreamsTracing.filter("filter-1", (key, value) -> true)).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
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);
assertThat(spanProcessor.tags()).containsEntry(KAFKA_STREAMS_FILTERED_TAG, "false");
// the filter transformer returns true so record is not dropped
MutableSpan spanOutput = testSpanHandler.takeRemoteSpan(PRODUCER);
assertThat(spanOutput.tags()).containsEntry("kafka.topic", outputTopic);
assertChildOf(spanOutput, spanProcessor);
streams.close();
streams.cleanUp();
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class ITKafkaStreamsTracing method should_create_spans_from_stream_with_tracing_mapValues.
@Test
public void should_create_spans_from_stream_with_tracing_mapValues() {
String inputTopic = testName.getMethodName() + "-input";
String outputTopic = testName.getMethodName() + "-output";
StreamsBuilder builder = new StreamsBuilder();
builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String())).transformValues(kafkaStreamsTracing.mapValues("mapValue-1", value -> {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
e.printStackTrace();
}
return value;
})).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
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);
MutableSpan spanOutput = testSpanHandler.takeRemoteSpan(PRODUCER);
assertThat(spanOutput.tags()).containsEntry("kafka.topic", outputTopic);
assertChildOf(spanOutput, spanProcessor);
streams.close();
streams.cleanUp();
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class ITKafkaStreamsTracing method should_create_spans_from_stream_with_tracing_filter_not_predicate_false.
@Test
public void should_create_spans_from_stream_with_tracing_filter_not_predicate_false() {
String inputTopic = testName.getMethodName() + "-input";
String outputTopic = testName.getMethodName() + "-output";
StreamsBuilder builder = new StreamsBuilder();
builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String())).transform(kafkaStreamsTracing.filterNot("filterNot-2", (key, value) -> false)).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
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);
assertThat(spanProcessor.tags()).containsEntry(KAFKA_STREAMS_FILTERED_TAG, "false");
// the filter transformer returns true so record is not dropped
MutableSpan spanOutput = testSpanHandler.takeRemoteSpan(PRODUCER);
assertThat(spanOutput.tags()).containsEntry("kafka.topic", outputTopic);
assertChildOf(spanOutput, spanProcessor);
streams.close();
streams.cleanUp();
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class ITKafkaStreamsTracing method should_create_spans_from_stream_with_tracing_transformer.
@Test
public void should_create_spans_from_stream_with_tracing_transformer() {
TransformerSupplier<String, String, KeyValue<String, String>> transformerSupplier = kafkaStreamsTracing.transformer("transformer-1", () -> new Transformer<String, String, KeyValue<String, String>>() {
ProcessorContext context;
@Override
public void init(ProcessorContext context) {
this.context = context;
}
@Override
public KeyValue<String, String> transform(String key, String value) {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
e.printStackTrace();
}
return KeyValue.pair(key, value);
}
@Override
public void close() {
}
});
String inputTopic = testName.getMethodName() + "-input";
String outputTopic = testName.getMethodName() + "-output";
StreamsBuilder builder = new StreamsBuilder();
builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String())).transform(transformerSupplier).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
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);
MutableSpan spanOutput = testSpanHandler.takeRemoteSpan(PRODUCER);
assertThat(spanOutput.tags()).containsEntry("kafka.topic", outputTopic);
assertChildOf(spanOutput, spanProcessor);
streams.close();
streams.cleanUp();
}
use of brave.handler.MutableSpan in project brave by openzipkin.
the class ITKafkaStreamsTracing method should_create_spans_from_stream_with_tracing_peek.
@Test
public void should_create_spans_from_stream_with_tracing_peek() {
String inputTopic = testName.getMethodName() + "-input";
String outputTopic = testName.getMethodName() + "-output";
long now = System.currentTimeMillis();
StreamsBuilder builder = new StreamsBuilder();
builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String())).transformValues(kafkaStreamsTracing.peek("peek-1", (key, value) -> {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
e.printStackTrace();
}
tracing.tracer().currentSpan().annotate(now, "test");
})).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
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);
assertThat(spanProcessor.annotations()).contains(entry(now, "test"));
MutableSpan spanOutput = testSpanHandler.takeRemoteSpan(PRODUCER);
assertThat(spanOutput.tags()).containsEntry("kafka.topic", outputTopic);
assertChildOf(spanOutput, spanProcessor);
streams.close();
streams.cleanUp();
}
Aggregations