Search in sources :

Example 16 with TraceContext

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

the class TracerTest method join_setsShared.

/**
 * When we join a sampled request, we are sharing the same trace identifiers.
 */
@Test
public void join_setsShared() {
    TraceContext fromIncomingRequest = tracer.newTrace().context();
    tracer.joinSpan(fromIncomingRequest).start().finish();
    assertThat(spans.get(0).shared()).isTrue();
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 17 with TraceContext

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

the class TracerTest method toSpan_noop.

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

Example 18 with TraceContext

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

the class TracerTest method nextSpan_extractedTraceContext.

@Test
public void nextSpan_extractedTraceContext() {
    TraceContext traceContext = TraceContext.newBuilder().traceId(1L).spanId(2L).build();
    TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(traceContext);
    assertThat(tracer.nextSpan(extracted).context()).extracting(TraceContext::traceId, TraceContext::parentId).containsExactly(1L, 2L);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Test(org.junit.Test)

Example 19 with TraceContext

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

the class TracerTest method toString_withSpanInFlight.

@Test
public void toString_withSpanInFlight() {
    TraceContext context = TraceContext.newBuilder().traceId(1L).spanId(10L).sampled(true).build();
    Span span = tracer.toSpan(context);
    // didn't set anything else! this is to help ensure no NPE
    span.start(1L);
    assertThat(tracer).hasToString("Tracer{inFlight=[{\"traceId\":\"0000000000000001\",\"id\":\"000000000000000a\",\"timestamp\":1,\"localEndpoint\":{\"serviceName\":\"my-service\"}}], reporter=MyReporter{}}");
    span.finish();
    assertThat(tracer).hasToString("Tracer{reporter=MyReporter{}}");
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 20 with TraceContext

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

the class TracerTest method join_createsChildWhenUnsupported.

@Test
public void join_createsChildWhenUnsupported() {
    tracer = Tracing.newBuilder().supportsJoin(false).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 : 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