Search in sources :

Example 6 with SpanHandler

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);
}
Also used : SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 7 with SpanHandler

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);
}
Also used : SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 8 with SpanHandler

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) {
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) Cause(brave.handler.SpanHandler.Cause) TraceContext(brave.propagation.TraceContext) SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 9 with SpanHandler

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);
}
Also used : SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 10 with SpanHandler

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);
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) SpanHandler(brave.handler.SpanHandler) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Aggregations

SpanHandler (brave.handler.SpanHandler)15 Test (org.junit.Test)11 MutableSpan (brave.handler.MutableSpan)8 TraceContext (brave.propagation.TraceContext)8 TestSpanHandler (brave.test.TestSpanHandler)6 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)4 FinishedSpanHandler (brave.handler.FinishedSpanHandler)3 CurrentTraceContext (brave.propagation.CurrentTraceContext)2 ArrayList (java.util.ArrayList)2 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)2 Clock (brave.Clock)1 ScopedSpan (brave.ScopedSpan)1 Tracing (brave.Tracing)1 Cause (brave.handler.SpanHandler.Cause)1 Nullable (brave.internal.Nullable)1 Arrays.asList (java.util.Arrays.asList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Before (org.junit.Before)1