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);
}
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);
}
}
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();
}
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();
}
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();
}
Aggregations