Search in sources :

Example 36 with SpanInScope

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);
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Test(org.junit.Test)

Example 37 with SpanInScope

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");
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 38 with SpanInScope

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);
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 39 with SpanInScope

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();
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 40 with SpanInScope

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);
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Aggregations

SpanInScope (brave.Tracer.SpanInScope)55 Span (brave.Span)34 Test (org.junit.Test)23 MutableSpan (brave.handler.MutableSpan)13 MockResponse (okhttp3.mockwebserver.MockResponse)4 Tracer (brave.Tracer)3 TopicPublisher (javax.jms.TopicPublisher)3 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)2 RequestContext (com.netflix.zuul.context.RequestContext)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 Destination (javax.jms.Destination)2 Response (javax.ws.rs.core.Response)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 HasSpan.hasSpan (org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan)2 Request (org.apache.cxf.tracing.brave.internal.HttpAdapterFactory.Request)2 BraveClientProvider (org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 Tracing (brave.Tracing)1