Search in sources :

Example 1 with SpanInScope

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

the class ITHttpClient method propagatesExtra_unsampledTrace.

@Test
public void propagatesExtra_unsampledTrace() throws Exception {
    Tracer tracer = httpTracing.tracing().tracer();
    server.enqueue(new MockResponse());
    brave.Span parent = tracer.newTrace(SamplingFlags.NOT_SAMPLED).name("test").start();
    try (SpanInScope ws = tracer.withSpanInScope(parent)) {
        ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
        get(client, "/foo");
    } finally {
        parent.finish();
    }
    assertThat(server.takeRequest().getHeader(EXTRA_KEY)).isEqualTo("joey");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Tracer(brave.Tracer) SpanInScope(brave.Tracer.SpanInScope) Test(org.junit.Test)

Example 2 with SpanInScope

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

the class BraveSpanBuilder method startActive.

@Override
public Scope startActive(boolean finishOnClose) {
    BraveSpan span = startManual();
    SpanInScope delegate = tracer.withSpanInScope(span.delegate);
    return new Scope() {

        @Override
        public void close() {
            if (finishOnClose)
                span.finish();
            delegate.close();
        }

        @Override
        public io.opentracing.Span span() {
            return span;
        }
    };
}
Also used : Scope(io.opentracing.Scope) SpanInScope(brave.Tracer.SpanInScope) SpanInScope(brave.Tracer.SpanInScope)

Example 3 with SpanInScope

use of brave.Tracer.SpanInScope in project incubator-servicecomb-java-chassis by apache.

the class ZipkinTracingHandler method handle.

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    Span span = tracingDelegate.createSpan(invocation);
    try (SpanInScope scope = tracer.tracer().withSpanInScope(span)) {
        LOGGER.debug("{}: Generated tracing span for {}", tracingDelegate.name(), invocation.getOperationName());
        invocation.next(onResponse(invocation, asyncResp, span));
    } catch (Exception e) {
        LOGGER.debug("{}: Failed invocation on {}", tracingDelegate.name(), invocation.getOperationName(), e);
        tracingDelegate.onResponse(span, null, e);
        throw e;
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 4 with SpanInScope

use of brave.Tracer.SpanInScope in project spring-cloud-sleuth by spring-cloud.

the class TraceRunnable method run.

@Override
public void run() {
    Throwable error = null;
    try (SpanInScope ws = this.tracer.withSpanInScope(this.span.start())) {
        this.delegate.run();
    } catch (RuntimeException | Error e) {
        error = e;
        throw e;
    } finally {
        this.errorParser.parseErrorTags(this.span.customizer(), error);
        this.span.finish();
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope)

Example 5 with SpanInScope

use of brave.Tracer.SpanInScope in project tutorials by eugenp.

the class SleuthService method doSomeWorkNewSpan.

public void doSomeWorkNewSpan() throws InterruptedException {
    logger.info("I'm in the original span");
    Span newSpan = tracer.newTrace().name("newSpan").start();
    try (SpanInScope ws = tracer.withSpanInScope(newSpan.start())) {
        Thread.sleep(1000L);
        logger.info("I'm in the new span doing some cool work that needs its own span");
    } finally {
        newSpan.finish();
    }
    logger.info("I'm in the original span");
}
Also used : 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