use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method nextSpan_extractedExtra_childOfCurrent.
@Test
public void nextSpan_extractedExtra_childOfCurrent() {
Span parent = tracer.newTrace();
TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.newBuilder(EMPTY).addExtra(1L).build();
try (SpanInScope ws = tracer.withSpanInScope(parent)) {
assertThat(tracer.nextSpan(extracted).context().extra()).containsExactly(1L);
}
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method startScopedSpan_getsExtraFromPropagationFactory.
@Test
public void startScopedSpan_getsExtraFromPropagationFactory() {
propagationFactory = baggageFactory;
Span parent = tracer.nextSpan();
BAGGAGE_FIELD.updateValue(parent.context(), "napkin");
ScopedSpan scoped;
try (SpanInScope scope = tracer.withSpanInScope(parent)) {
scoped = tracer.startScopedSpan("foo");
scoped.finish();
}
assertThat(BAGGAGE_FIELD.getValue(scoped.context())).isEqualTo("napkin");
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method withSpanInScope_nested.
@Test
public void withSpanInScope_nested() {
Span parent = tracer.newTrace();
try (SpanInScope wsParent = tracer.withSpanInScope(parent)) {
Span child = tracer.newChild(parent.context());
try (SpanInScope wsChild = tracer.withSpanInScope(child)) {
assertThat(tracer.currentSpan()).isEqualTo(child);
}
// old parent reverted
assertThat(tracer.currentSpan()).isEqualTo(parent);
}
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method withNoopSpanInScope.
@Test
public void withNoopSpanInScope() {
Span current = tracer.withSampler(Sampler.NEVER_SAMPLE).nextSpan();
try (SpanInScope ws = tracer.withSpanInScope(current)) {
assertThat(tracer.currentSpan()).isEqualTo(current);
assertThat(tracer.currentSpanCustomizer()).isNotEqualTo(current).isEqualTo(NoopSpanCustomizer.INSTANCE);
}
// context was cleared
assertThat(tracer.currentSpan()).isNull();
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method withSpanInScope_clear.
@Test
public void withSpanInScope_clear() {
Span parent = tracer.newTrace();
try (SpanInScope wsParent = tracer.withSpanInScope(parent)) {
try (SpanInScope clearScope = tracer.withSpanInScope(null)) {
assertThat(tracer.currentSpan()).isNull();
assertThat(tracer.currentSpanCustomizer()).isEqualTo(NoopSpanCustomizer.INSTANCE);
}
// old parent reverted
assertThat(tracer.currentSpan()).isEqualTo(parent);
}
}
Aggregations