Search in sources :

Example 6 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class HttpClientHandlerTest method handleSend_injectsTheTraceContext_onTheCarrier.

@Test
public void handleSend_injectsTheTraceContext_onTheCarrier() {
    Object customCarrier = new Object();
    TraceContext context = handler.handleSend(injector, customCarrier, request).context();
    verify(injector).inject(context, customCarrier);
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 7 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class HttpClientHandlerTest method handleSend_injectsTheTraceContext.

@Test
public void handleSend_injectsTheTraceContext() {
    TraceContext context = handler.handleSend(injector, request).context();
    verify(injector).inject(context, request);
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 8 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class HttpServerHandlerTest method handleReceive_reusesTraceId.

@Test
public void handleReceive_reusesTraceId() {
    HttpTracing httpTracing = HttpTracing.create(Tracing.newBuilder().supportsJoin(false).spanReporter(spans::add).build());
    tracer = httpTracing.tracing().tracer();
    handler = HttpServerHandler.create(httpTracing, adapter);
    TraceContext incomingContext = tracer.nextSpan().context();
    when(extractor.extract(request)).thenReturn(TraceContextOrSamplingFlags.create(incomingContext));
    handler.handleReceive(extractor, request).finish();
    assertThat(spans.get(0).shared()).isNull();
    assertThat(spans.get(0).traceId()).isEqualTo(incomingContext.traceIdString());
    assertThat(spans.get(0).parentId()).isEqualTo(HexCodec.toLowerHex(incomingContext.spanId()));
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 9 with TraceContext

use of brave.propagation.TraceContext 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 10 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class KafkaTracingTest method nextSpan_should_use_span_from_headers_as_parent.

@Test
public void nextSpan_should_use_span_from_headers_as_parent() {
    addB3Headers(fakeRecord);
    Span span = kafkaTracing.nextSpan(fakeRecord);
    TraceContext context = span.context();
    assertThat(HexCodec.toLowerHex(context.traceId())).isEqualTo(TRACE_ID);
    assertThat(HexCodec.toLowerHex(context.parentId())).isEqualTo(SPAN_ID);
    assertThat(context.sampled()).isEqualTo(true);
}
Also used : TraceContext(brave.propagation.TraceContext) Span(brave.Span) Test(org.junit.Test)

Aggregations

TraceContext (brave.propagation.TraceContext)54 Test (org.junit.Test)46 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)21 CurrentTraceContext (brave.propagation.CurrentTraceContext)10 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Span (brave.Span)4 Tracer (brave.Tracer)4 Tracing (brave.Tracing)4 ThreadContextCurrentTraceContext (brave.context.log4j2.ThreadContextCurrentTraceContext)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 After (org.junit.After)4 Endpoint (zipkin2.Endpoint)4 Span (zipkin2.Span)4 Platform (brave.internal.Platform)3 Propagation (brave.propagation.Propagation)3 Reference (java.lang.ref.Reference)3