Search in sources :

Example 16 with InvocationContext

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;
}
Also used : DefaultInvocationContext(com.palantir.tritium.event.DefaultInvocationContext) InvocationContext(com.palantir.tritium.event.InvocationContext)

Example 17 with InvocationContext

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"));
}
Also used : DefaultInvocationContext(com.palantir.tritium.event.DefaultInvocationContext) InvocationContext(com.palantir.tritium.event.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 18 with InvocationContext

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");
}
Also used : DefaultInvocationContext(com.palantir.tritium.event.DefaultInvocationContext) InvocationContext(com.palantir.tritium.event.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 19 with InvocationContext

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();
}
Also used : InvocationContext(com.palantir.tritium.event.InvocationContext) Span(com.palantir.tracing.api.Span) Test(org.junit.jupiter.api.Test)

Example 20 with InvocationContext

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();
}
Also used : InvocationContext(com.palantir.tritium.event.InvocationContext) Test(org.junit.jupiter.api.Test)

Aggregations

InvocationContext (com.palantir.tritium.event.InvocationContext)20 Test (org.junit.jupiter.api.Test)16 DefaultInvocationContext (com.palantir.tritium.event.DefaultInvocationContext)14 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)5 Nullable (javax.annotation.Nullable)4 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Span (com.palantir.tracing.api.Span)2 TestImplementation (com.palantir.tritium.test.TestImplementation)2 TestInterface (com.palantir.tritium.test.TestInterface)2 Set (java.util.Set)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Goethe (com.palantir.goethe.Goethe)1 GoetheException (com.palantir.goethe.GoetheException)1 Preconditions (com.palantir.logsafe.Preconditions)1 Instrument (com.palantir.tritium.annotations.Instrument)1 InstrumentationBuilder (com.palantir.tritium.annotations.internal.InstrumentationBuilder)1 InstrumentationFilter (com.palantir.tritium.api.event.InstrumentationFilter)1