Search in sources :

Example 11 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracerTest method withSpanInScope.

@Test
public void withSpanInScope() {
    Span current = tracer.newTrace();
    try (SpanInScope ws = tracer.withSpanInScope(current)) {
        assertThat(tracer.currentSpan()).isEqualTo(current);
        assertThat(tracer.currentSpanCustomizer()).isNotEqualTo(current).isNotEqualTo(NoopSpanCustomizer.INSTANCE);
    }
    // context was cleared
    assertThat(tracer.currentSpan()).isNull();
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 12 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracerTest method simulateInProcessPropagation.

/**
 * Must be a separate method from the test method to allow for local variables to be garbage
 * collected
 */
private static void simulateInProcessPropagation(Tracer tracer1, Tracer tracer2) {
    Span span1 = tracer1.newTrace();
    span1.start();
    // Pretend we're on child thread
    Tracer.SpanInScope spanInScope = tracer2.withSpanInScope(span1);
    // Back on original thread
    span1.finish();
    // Pretend we're on child thread
    Span span2 = tracer2.currentSpan();
    spanInScope.close();
}
Also used : MutableSpan(brave.handler.MutableSpan) SpanInScope(brave.Tracer.SpanInScope)

Example 13 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class NoopSpanTest method equals_lazySpan_notSameContext.

@Test
public void equals_lazySpan_notSameContext() {
    Span current;
    try (SpanInScope ws = tracer.withSpanInScope(tracer.newTrace())) {
        current = tracer.currentSpan();
    }
    assertThat(span).isNotEqualTo(current);
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 14 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class NoopSpanTest method equals_lazySpan_sameContext.

@Test
public void equals_lazySpan_sameContext() {
    Span current;
    try (SpanInScope ws = tracer.withSpanInScope(span)) {
        current = tracer.currentSpan();
    }
    assertThat(span).isEqualTo(current);
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 15 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracingInterceptor method intercept.

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
    RequestWrapper request = new RequestWrapper(chain.request());
    Span span = handler.handleSend(request);
    Response response = null;
    Throwable error = null;
    try (SpanInScope ws = tracer.withSpanInScope(span)) {
        return response = chain.proceed(request.build());
    } catch (Throwable e) {
        error = e;
        throw e;
    } finally {
        handler.handleReceive(new ResponseWrapper(response, error), span);
    }
}
Also used : Response(okhttp3.Response) HttpClientResponse(brave.http.HttpClientResponse) SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

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