Search in sources :

Example 41 with TraceContext

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

the class TracerTest method toSpan.

@Test
public void toSpan() {
    TraceContext context = tracer.newTrace().context();
    assertThat(tracer.toSpan(context)).isInstanceOf(RealSpan.class).extracting(Span::context).containsExactly(context);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 42 with TraceContext

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

Example 43 with TraceContext

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

the class TracerTest method newChild_noop.

@Test
public void newChild_noop() {
    TraceContext parent = tracer.newTrace().context();
    tracer.noop.set(true);
    assertThat(tracer.newChild(parent)).isInstanceOf(NoopSpan.class);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 44 with TraceContext

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

the class TracerTest method join_ensuresSampling.

@Test
public void join_ensuresSampling() {
    TraceContext notYetSampled = tracer.newTrace().context().toBuilder().sampled(null).build();
    assertThat(tracer.joinSpan(notYetSampled).context()).isEqualTo(notYetSampled.toBuilder().sampled(true).build());
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 45 with TraceContext

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

the class TracerTest method join_noop.

@Test
public void join_noop() {
    TraceContext fromIncomingRequest = tracer.newTrace().context();
    tracer.noop.set(true);
    assertThat(tracer.joinSpan(fromIncomingRequest)).isInstanceOf(NoopSpan.class);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) 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