use of brave.handler.SpanHandler in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method multiple_shortCircuitWhenFirstReturnsFalse.
@Test
public void multiple_shortCircuitWhenFirstReturnsFalse() {
SpanHandler[] handlers = new SpanHandler[2];
handlers[0] = one;
handlers[1] = two;
SpanHandler handler = NoopAwareSpanHandler.create(handlers, noop);
handler.end(context, span, Cause.FINISHED);
verify(one).end(context, span, Cause.FINISHED);
verify(two, never()).end(context, span, Cause.FINISHED);
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method create_multiple.
@Test
public void create_multiple() {
SpanHandler[] handlers = new SpanHandler[2];
handlers[0] = one;
handlers[1] = two;
SpanHandler handler = NoopAwareSpanHandler.create(handlers, noop);
assertThat(handler).extracting("delegate.handlers").asInstanceOf(InstanceOfAssertFactories.array(SpanHandler[].class)).containsExactly(one, two);
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method doesntCrashOnNonFatalThrowable.
@Test
public void doesntCrashOnNonFatalThrowable() {
Throwable[] toThrow = new Throwable[1];
SpanHandler handler = NoopAwareSpanHandler.create(new SpanHandler[] { new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
doThrowUnsafely(toThrow[0]);
return true;
}
} }, noop);
toThrow[0] = new RuntimeException();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
toThrow[0] = new Exception();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
toThrow[0] = new Error();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
// fatal
toThrow[0] = new StackOverflowError();
try {
// assertThatThrownBy doesn't work with StackOverflowError
handler.end(context, span, Cause.FINISHED);
failBecauseExceptionWasNotThrown(StackOverflowError.class);
} catch (StackOverflowError e) {
}
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method honorsNoop.
@Test
public void honorsNoop() {
SpanHandler handler = NoopAwareSpanHandler.create(new SpanHandler[] { one }, noop);
noop.set(true);
handler.end(context, span, Cause.FINISHED);
verify(one, never()).end(context, span, Cause.FINISHED);
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class ITHttpServer method spanHandlerSeesError.
void spanHandlerSeesError(String path) throws IOException {
ConcurrentLinkedDeque<Throwable> caughtThrowables = new ConcurrentLinkedDeque<>();
httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).clearSpanHandlers().addSpanHandler(new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
Throwable error = span.error();
if (error != null) {
caughtThrowables.add(error);
} else {
caughtThrowables.add(new RuntimeException("Unexpected additional call to end"));
}
return true;
}
}).addSpanHandler(testSpanHandler).build());
init();
// If this passes, a span was reported with an error
httpStatusCodeTagMatchesResponse_onUncaughtException(path, ".*not ready");
assertThat(caughtThrowables).withFailMessage("Span finished with error, but caughtThrowables empty").isNotEmpty();
if (caughtThrowables.size() > 1) {
for (Throwable throwable : caughtThrowables) {
Logger.getAnonymousLogger().log(Level.SEVERE, "multiple calls to finish", throwable);
}
assertThat(caughtThrowables).hasSize(1);
}
}
Aggregations