Search in sources :

Example 51 with SpanInScope

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

the class TracingMessageProducer method publish.

@Override
public void publish(Message message) throws JMSException {
    checkTopicPublisher();
    TopicPublisher tp = (TopicPublisher) delegate;
    Span span = createAndStartProducerSpan(message, destination(message));
    SpanInScope ws = tracer.withSpanInScope(span);
    Throwable error = null;
    try {
        tp.publish(message);
    } catch (Throwable t) {
        propagateIfFatal(t);
        error = t;
        throw t;
    } finally {
        if (error != null)
            span.error(error);
        span.finish();
        ws.close();
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) TopicPublisher(javax.jms.TopicPublisher) Span(brave.Span)

Example 52 with SpanInScope

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

the class TracingMessageProducer method send.

@Override
public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
    Span span = createAndStartProducerSpan(message, destination(message));
    // animal-sniffer mistakes this for AutoCloseable
    SpanInScope ws = tracer.withSpanInScope(span);
    Throwable error = null;
    try {
        delegate.send(message, deliveryMode, priority, timeToLive);
    } catch (Throwable t) {
        propagateIfFatal(t);
        error = t;
        throw t;
    } finally {
        if (error != null)
            span.error(error);
        span.finish();
        ws.close();
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 53 with SpanInScope

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

the class TracingMessageProducer method send.

/* @Override JMS 2.0 method: Intentionally no override to ensure JMS 1.1 works! */
@JMS2_0
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException {
    Span span = createAndStartProducerSpan(message, destination);
    completionListener = TracingCompletionListener.create(completionListener, destination, span, current);
    SpanInScope ws = tracer.withSpanInScope(span);
    Throwable error = null;
    try {
        delegate.send(destination, message, deliveryMode, priority, timeToLive, completionListener);
    } catch (Throwable t) {
        propagateIfFatal(t);
        error = t;
        throw t;
    } finally {
        if (error != null)
            span.error(error).finish();
        ws.close();
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 54 with SpanInScope

use of brave.Tracer.SpanInScope in project java-chassis by ServiceComb.

the class ZipkinTracingAdviserTest method startsNewChildSpan.

@SuppressWarnings({ "unused", "try" })
@Test
public void startsNewChildSpan() {
    CyclicBarrier cyclicBarrier = new CyclicBarrier(nThreads);
    CompletableFuture<?>[] futures = (CompletableFuture<?>[]) Array.newInstance(CompletableFuture.class, nThreads);
    for (int i = 0; i < nThreads; i++) {
        futures[i] = CompletableFuture.runAsync(() -> {
            Span currentSpan = tracing.tracer().newTrace().start();
            waitTillAllAreReady(cyclicBarrier);
            try (SpanInScope spanInScope = tracing.tracer().withSpanInScope(currentSpan)) {
                assertThat(tracingAdviser.invoke(spanName, path, supplier), is(expected));
            } catch (Throwable throwable) {
                fail(throwable.getMessage());
            } finally {
                currentSpan.finish();
            }
        }, Executors.newFixedThreadPool(nThreads));
    }
    CompletableFuture.allOf(futures).join();
    assertThat(traces.size(), is(nThreads));
    for (Queue<zipkin2.Span> queue : traces.values()) {
        zipkin2.Span child = queue.poll();
        assertThat(child.name(), is(spanName));
        zipkin2.Span parent = queue.poll();
        assertThat(child.parentId(), is(parent.id()));
        assertThat(child.traceId(), is(parent.traceId()));
        assertThat(tracedValues(child), contains(this.getClass().getCanonicalName()));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 55 with SpanInScope

use of brave.Tracer.SpanInScope in project java-chassis by ServiceComb.

the class ZipkinTracingHandler method handle.

@SuppressWarnings({ "try", "unused" })
@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)

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