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