use of brave.propagation.Propagation 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() throws Exception {
consumerTracing = KafkaTracing.create(Tracing.newBuilder().spanReporter(consumerSpans::add).propagationFactory(new Propagation.Factory() {
@Override
public <K> Propagation<K> create(Propagation.KeyFactory<K> keyFactory) {
return new TraceIdOnlyPropagation<>(keyFactory);
}
}).sampler(Sampler.ALWAYS_SAMPLE).build());
producerTracing = KafkaTracing.create(Tracing.newBuilder().spanReporter(producerSpans::add).propagationFactory(new Propagation.Factory() {
@Override
public <K> Propagation<K> create(Propagation.KeyFactory<K> keyFactory) {
return new TraceIdOnlyPropagation<>(keyFactory);
}
}).sampler(Sampler.ALWAYS_SAMPLE).build());
producer = createTracingProducer();
consumer = createTracingConsumer();
producer.send(new ProducerRecord<>(testName.getMethodName(), TEST_KEY, TEST_VALUE)).get();
ConsumerRecords<String, String> records = consumer.poll(10000);
assertThat(records).hasSize(1);
Span producerSpan = producerSpans.take();
Span consumerSpan = consumerSpans.take();
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.propagation.Propagation in project brave by openzipkin.
the class TracerTest method join_createsChildWhenUnsupportedByPropagation.
@Test
public void join_createsChildWhenUnsupportedByPropagation() {
tracer = Tracing.newBuilder().propagationFactory(new Propagation.Factory() {
@Override
public <K> Propagation<K> create(Propagation.KeyFactory<K> keyFactory) {
return B3Propagation.FACTORY.create(keyFactory);
}
}).spanReporter(spans::add).build().tracer();
TraceContext fromIncomingRequest = tracer.newTrace().context();
tracer.joinSpan(fromIncomingRequest).start().finish();
assertThat(spans.get(0).shared()).isNull();
assertThat(spans.get(0).parentId()).isEqualTo(HexCodec.toLowerHex(fromIncomingRequest.spanId()));
}
Aggregations