Search in sources :

Example 1 with Propagation

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());
    }
}
Also used : Propagation(brave.propagation.Propagation) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) TraceContext(brave.propagation.TraceContext) Span(zipkin2.Span) Test(org.junit.Test)

Example 2 with Propagation

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()));
}
Also used : B3Propagation(brave.propagation.B3Propagation) Propagation(brave.propagation.Propagation) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Aggregations

Propagation (brave.propagation.Propagation)2 TraceContext (brave.propagation.TraceContext)2 Test (org.junit.Test)2 B3Propagation (brave.propagation.B3Propagation)1 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 Span (zipkin2.Span)1