use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class RemotingCompatibleTracingInvocationEventHandler method preInvocation.
@Override
public InvocationContext preInvocation(@Nonnull Object instance, @Nonnull Method method, @Nonnull Object[] args) {
InvocationContext context = DefaultInvocationContext.of(instance, method, args);
String operationName = getOperationName(method);
tracer.startSpan(operationName);
return context;
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class LoggingInvocationEventHandlerTest method testLoggingOnFailure.
@Test
// CHECKSTYLE IGNORE IllegalThrows
@SuppressWarnings("checkstyle:illegalthrows")
public void testLoggingOnFailure() throws Throwable {
LoggingInvocationEventHandler handler = new LoggingInvocationEventHandler(getLogger(), LoggingLevel.INFO);
InvocationContext context = DefaultInvocationContext.of(this, Object.class.getDeclaredMethod("toString"), null);
handler.onFailure(context, new RuntimeException("cause"));
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class LoggingInvocationEventHandlerTest method testLoggingOnSuccess.
@Test
@SuppressWarnings("checkstyle:illegalthrows")
public void testLoggingOnSuccess() throws Throwable {
LoggingInvocationEventHandler handler = new LoggingInvocationEventHandler(getLogger(), LoggingLevel.INFO);
InvocationContext context = DefaultInvocationContext.of(this, Object.class.getDeclaredMethod("toString"), null);
handler.onSuccess(context, "result");
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class TracingInvocationEventHandlerTest method testFailure.
@Test
public void testFailure() {
InvocationContext context = handler.preInvocation(instance, method, args);
assertThat(Tracer.hasTraceId()).isTrue();
handler.onFailure(context, new RuntimeException("unexpected"));
ArgumentCaptor<Span> spanCaptor = ArgumentCaptor.forClass(Span.class);
verify(mockSpanObserver, times(1)).consume(spanCaptor.capture());
Span span = spanCaptor.getValue();
assertThat(span.getDurationNanoSeconds()).isGreaterThan(0L);
assertThat(Tracer.hasTraceId()).isFalse();
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class TracingInvocationEventHandlerTest method testPreInvocation.
@Test
public void testPreInvocation() {
long startNanoseconds = System.nanoTime();
InvocationContext context = handler.preInvocation(instance, method, args);
assertThat(context).isNotNull();
assertThat(context.getMethod()).isEqualTo(method);
assertThat(context.getArgs()).isEqualTo(args);
assertThat(context.getStartTimeNanos()).isGreaterThan(startNanoseconds);
assertThat(context.getStartTimeNanos()).isLessThan(System.nanoTime());
assertThat(Tracer.hasTraceId()).isTrue();
}
Aggregations