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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations