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(Message message, CompletionListener completionListener) throws JMSException {
Destination destination = destination(message);
Span span = createAndStartProducerSpan(message, destination);
// animal-sniffer mistakes this for AutoCloseable
SpanInScope ws = tracer.withSpanInScope(span);
Throwable error = null;
try {
delegate.send(message, TracingCompletionListener.create(completionListener, destination, span, current));
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} finally {
if (error != null)
span.error(error).finish();
ws.close();
}
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracingMessageProducer method send.
@Override
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
Span span = createAndStartProducerSpan(message, destination);
SpanInScope ws = tracer.withSpanInScope(span);
Throwable error = null;
try {
delegate.send(destination, message, deliveryMode, priority, timeToLive);
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} finally {
if (error != null)
span.error(error);
span.finish();
ws.close();
}
}
use of brave.Tracer.SpanInScope in project cxf by apache.
the class AbstractBraveProvider method startTraceSpan.
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) {
final Request request = HttpAdapterFactory.request(requestHeaders, uri, method);
final HttpServerAdapter<Request, ?> adapter = HttpServerAdapterFactory.create(request);
final HttpServerHandler<Request, ?> handler = HttpServerHandler.create(brave, adapter);
Span span = handler.handleReceive(brave.tracing().propagation().extractor(adapter::requestHeader), request);
// If the service resource is using asynchronous processing mode, the trace
// scope will be closed in another thread and as such should be detached.
SpanInScope scope = null;
if (isAsyncResponse() && span != null) {
// Do not modify the current context span
propagateContinuationSpan(span);
} else if (span != null) {
scope = brave.tracing().tracer().withSpanInScope(span);
}
return new TraceScopeHolder<TraceScope>(new TraceScope(span, scope), scope == null);
}
use of brave.Tracer.SpanInScope in project cxf by apache.
the class BraveTracingTest method testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient.
@Test
public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws Exception {
final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
final Span span = brave.tracer().nextSpan().name("test span").start();
try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
final Future<Response> f = client.async().get();
final Response r = f.get(1, TimeUnit.SECONDS);
assertEquals(Status.OK.getStatusCode(), r.getStatus());
assertThat(brave.tracer().currentSpan().context().spanId(), equalTo(span.context().spanId()));
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
} finally {
span.finish();
}
// Await till flush happens, usually a second is enough
await().atMost(Duration.ofSeconds(1L)).until(() -> TestSpanReporter.getAllSpans().size() == 4);
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}
use of brave.Tracer.SpanInScope in project cxf by apache.
the class BraveTracingTest method testThatProvidedSpanIsNotClosedWhenActive.
@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
final Span span = brave.tracer().nextSpan().name("test span").start();
try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
final Response r = client.get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
} finally {
span.finish();
}
// Await till flush happens, usually a second is enough
await().atMost(Duration.ofSeconds(1L)).until(() -> TestSpanReporter.getAllSpans().size() == 4);
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}
Aggregations