use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class CurrentSpanCustomizerTest method annotate.
@Test
public void annotate() {
span.start();
try (SpanInScope ws = tracing.tracer().withSpanInScope(span)) {
spanCustomizer.annotate("foo");
}
span.flush();
assertThat(spans.get(0).annotations()).extracting(Map.Entry::getValue).containsExactly("foo");
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracingProtocolExec method execute.
@Override
public CloseableHttpResponse execute(HttpRoute route, org.apache.http.client.methods.HttpRequestWrapper req, HttpClientContext context, HttpExecutionAware execAware) throws IOException, HttpException {
HttpRequestWrapper request = new HttpRequestWrapper(req, context.getTargetHost());
Span span = tracer.nextSpan(httpSampler, request);
context.setAttribute(Span.class.getName(), span);
CloseableHttpResponse response = null;
Throwable error = null;
try (SpanInScope ws = tracer.withSpanInScope(span)) {
return response = protocolExec.execute(route, req, context, execAware);
} catch (Throwable e) {
error = e;
throw e;
} finally {
handler.handleReceive(new HttpResponseWrapper(response, context, error), span);
}
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracingMessageListener method onMessage.
@Override
public void onMessage(Message message) {
Span listenerSpan = startMessageListenerSpan(message);
SpanInScope ws = tracer.withSpanInScope(listenerSpan);
Throwable error = null;
try {
delegate.onMessage(message);
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} finally {
if (error != null)
listenerSpan.error(error);
listenerSpan.finish();
ws.close();
}
}
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, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException {
Destination destination = destination(message);
Span span = createAndStartProducerSpan(message, destination);
completionListener = TracingCompletionListener.create(completionListener, destination, span, current);
// animal-sniffer mistakes this for AutoCloseable
SpanInScope ws = tracer.withSpanInScope(span);
Throwable error = null;
try {
delegate.send(message, deliveryMode, priority, timeToLive, completionListener);
} 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.
void send(SendDestination sendDestination, Destination destination, Message message) throws JMSException {
Span span = createAndStartProducerSpan(message, destination);
// animal-sniffer mistakes this for AutoCloseable
SpanInScope ws = tracer.withSpanInScope(span);
Throwable error = null;
try {
sendDestination.apply(delegate, destination, message);
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} finally {
if (error != null)
span.error(error);
span.finish();
ws.close();
}
}
Aggregations