Search in sources :

Example 1 with ErrorEvent

use of com.newrelic.agent.introspec.ErrorEvent in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testErrorOutsideTransaction.

@Test
public void testErrorOutsideTransaction() {
    Throwable throwable = new Throwable("MyTest");
    ServiceFactory.getRPMService().getErrorService().reportException(throwable);
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(0, txNames.size());
    Collection<Error> errors1 = impl.getErrors();
    Assert.assertEquals(1, errors1.size());
    Error error1 = errors1.iterator().next();
    Assert.assertEquals("MyTest", error1.getErrorMessage());
    Assert.assertEquals(throwable, error1.getThrowable());
    Collection<ErrorEvent> events = impl.getErrorEvents();
    Assert.assertEquals(1, events.size());
    ErrorEvent event = events.iterator().next();
    // well that seems wrong - but that seems to be what we name all errors
    Assert.assertEquals("TransactionError", event.getType());
    Assert.assertEquals("MyTest", event.getErrorMessage());
    Assert.assertEquals("java.lang.Throwable", event.getErrorClass());
    Assert.assertEquals("Unknown", event.getTransactionName());
}
Also used : ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Error(com.newrelic.agent.introspec.Error) Test(org.junit.Test)

Example 2 with ErrorEvent

use of com.newrelic.agent.introspec.ErrorEvent in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testErrorInTx.

@Test
public void testErrorInTx() {
    // transaction
    Transaction.getTransaction();
    Tracer rootTracer = createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Throwable throwable = new Throwable("MyTest");
    Transaction.getTransaction().setThrowable(throwable, TransactionErrorPriority.TRACER, false);
    rootTracer.finish(RETURN_OPCODE, 0);
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(1, txNames.size());
    Assert.assertEquals("OtherTransaction/rootOnly", txNames.iterator().next());
    Collection<Error> errors1 = impl.getErrors();
    Collection<Error> errors2 = impl.getErrorsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, errors1.size());
    Assert.assertEquals(1, errors2.size());
    Error error1 = errors1.iterator().next();
    Assert.assertEquals(error1, errors2.iterator().next());
    Assert.assertEquals("MyTest", error1.getErrorMessage());
    Assert.assertEquals(throwable, error1.getThrowable());
    Assert.assertEquals(1, impl.getTransactionEvents(txNames.iterator().next()).size());
    Collection<ErrorEvent> events = impl.getErrorEvents();
    Assert.assertEquals(1, events.size());
    ErrorEvent event1 = events.iterator().next();
    Assert.assertEquals("TransactionError", event1.getType());
    Assert.assertEquals("MyTest", event1.getErrorMessage());
    Assert.assertEquals("java.lang.Throwable", event1.getErrorClass());
    Assert.assertEquals("OtherTransaction/rootOnly", event1.getTransactionName());
    Collection<ErrorEvent> txEvents = impl.getErrorEventsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, txEvents.size());
    Event event2 = events.iterator().next();
    Assert.assertEquals("TransactionError", event2.getType());
    Assert.assertEquals(event1, event2);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Error(com.newrelic.agent.introspec.Error) Event(com.newrelic.agent.introspec.Event) ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Test(org.junit.Test)

Example 3 with ErrorEvent

use of com.newrelic.agent.introspec.ErrorEvent in project newrelic-java-agent by newrelic.

the class BasicRequestsTest method testUncaughtException.

@Test
public void testUncaughtException() {
    try {
        client.throwException("Blocking");
    } catch (Exception e) {
    }
    String fullMethod = "helloworld.Greeter/ThrowException";
    String clientTxName = "OtherTransaction/Custom/app.TestClient/throwException";
    String serverTxName = "WebTransaction/gRPC/helloworld.Greeter/ThrowException";
    ValidationHelper.validateExceptionGrpcInteraction(server, clientTxName, serverTxName, fullMethod, "UNARY", "Blocking", 2);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Collection<ErrorEvent> errorEvents = introspector.getErrorEvents();
    CatHelper.verifyOneSuccessfulCat(introspector, clientTxName, serverTxName);
    assertEquals(2, errorEvents.size());
}
Also used : ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

Example 4 with ErrorEvent

use of com.newrelic.agent.introspec.ErrorEvent in project newrelic-java-agent by newrelic.

the class GrpcErrorsTest method testCaughtException.

@Test
public void testCaughtException() {
    try {
        client.throwCaughtException("Blocking");
    } catch (Exception e) {
    }
    String fullMethod = "helloworld.Greeter/ThrowCaughtException";
    String clientTxName = "OtherTransaction/Custom/app.TestClient/throwCaughtException";
    String serverTxName = "WebTransaction/gRPC/helloworld.Greeter/ThrowCaughtException";
    ValidationHelper.validateExceptionGrpcInteraction(server, clientTxName, serverTxName, fullMethod, "UNARY", "Blocking", 10);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Collection<ErrorEvent> errorEvents = introspector.getErrorEvents();
    CatHelper.verifyOneSuccessfulCat(introspector, clientTxName, serverTxName);
    // Disabling the gRPC error capture prevents error events from being created
    assertEquals(0, errorEvents.size());
}
Also used : ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

Example 5 with ErrorEvent

use of com.newrelic.agent.introspec.ErrorEvent in project newrelic-java-agent by newrelic.

the class BasicRequestsTest method testCaughtException.

@Test
public void testCaughtException() {
    try {
        client.throwCaughtException("Blocking");
    } catch (Exception e) {
    }
    String fullMethod = "helloworld.Greeter/ThrowCaughtException";
    String clientTxName = "OtherTransaction/Custom/app.TestClient/throwCaughtException";
    String serverTxName = "WebTransaction/gRPC/helloworld.Greeter/ThrowCaughtException";
    ValidationHelper.validateExceptionGrpcInteraction(server, clientTxName, serverTxName, fullMethod, "UNARY", "Blocking", 10);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Collection<ErrorEvent> errorEvents = introspector.getErrorEvents();
    CatHelper.verifyOneSuccessfulCat(introspector, clientTxName, serverTxName);
    assertEquals(1, errorEvents.size());
}
Also used : ErrorEvent(com.newrelic.agent.introspec.ErrorEvent) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

Aggregations

ErrorEvent (com.newrelic.agent.introspec.ErrorEvent)6 Test (org.junit.Test)6 Introspector (com.newrelic.agent.introspec.Introspector)4 Error (com.newrelic.agent.introspec.Error)2 Event (com.newrelic.agent.introspec.Event)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1