Search in sources :

Example 46 with TraceContext

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

the class TracerTest method newChild_unsampledIsNoop.

@Test
public void newChild_unsampledIsNoop() {
    TraceContext unsampled = tracer.newTrace().context().toBuilder().sampled(false).build();
    assertThat(tracer.newChild(unsampled)).isInstanceOf(NoopSpan.class);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 47 with TraceContext

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

the class TracerTest method toSpan_unsampledIsNoop.

@Test
public void toSpan_unsampledIsNoop() {
    TraceContext unsampled = tracer.newTrace().context().toBuilder().sampled(false).build();
    assertThat(tracer.toSpan(unsampled)).isInstanceOf(NoopSpan.class);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 48 with TraceContext

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

the class TracerTest method nextSpan_extractedTraceContext_extra.

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

Example 49 with TraceContext

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

the class BraveTracer method extract.

@Override
public <C> BraveSpanContext extract(Format<C> format, C carrier) {
    if (format != Format.Builtin.HTTP_HEADERS) {
        throw new UnsupportedOperationException(format.toString());
    }
    TraceContextOrSamplingFlags extracted = extractor.extract(new TextMapView(propagationKeys, (TextMap) carrier));
    TraceContext context = extracted.context() != null ? tracer.joinSpan(extracted.context()).context() : tracer.nextSpan(extracted).context();
    return new BraveSpanContext(context);
}
Also used : TraceContext(brave.propagation.TraceContext) TextMap(io.opentracing.propagation.TextMap) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags)

Example 50 with TraceContext

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

the class MutableSpanMapTest method getOrCreate_resolvesHashCodeCollisions.

@Test
public void getOrCreate_resolvesHashCodeCollisions() {
    // intentionally clash on hashCode, but not equals
    TraceContext context1 = context.toBuilder().spanId(1).build();
    TraceContext context2 = context.toBuilder().spanId(-2L).build();
    // sanity check
    assertThat(context1.hashCode()).isEqualTo(context2.hashCode());
    assertThat(context1).isNotEqualTo(context2);
    assertThat(map.getOrCreate(context1)).isNotEqualTo(map.getOrCreate(context2));
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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