Search in sources :

Example 1 with TracedError

use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.

the class RequestUriConfigTests method runTracedErrorTest.

public void runTracedErrorTest(RequestUriConfigTransactionTest test) throws Exception {
    setupConfig(test);
    // run a transaction
    Tracer requestDispatcherTracer = startDispatcherTracer(test.getTxnName());
    DefaultTracer defaultTracer = startTracer();
    NewRelicApiImplementation.initialize();
    AgentBridge.publicApi.noticeError("error");
    defaultTracer.finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    MockRPMService mockRPMService = runHarvest();
    // verify results
    List<TracedError> errorTraces = mockRPMService.getErrorService().getAndClearTracedErrors();
    assertFalse(errorTraces.isEmpty());
    for (TracedError trace : errorTraces) {
        Writer writer = new StringWriter();
        trace.writeJSONString(writer);
        JSONParser parser = new JSONParser();
        JSONArray parsedError = (JSONArray) parser.parse(writer.toString());
        matchUri(test.getExpectedUriValues(), (String) ((JSONObject) parsedError.get(4)).get("request_uri"));
    }
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) TracedError(com.newrelic.agent.errors.TracedError) StringWriter(java.io.StringWriter) JSONObject(org.json.simple.JSONObject) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) MockRPMService(com.newrelic.agent.MockRPMService) Writer(java.io.Writer) StringWriter(java.io.StringWriter)

Example 2 with TracedError

use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorThrowableParamsOutsideTransaction.

@Test
public void testNoticeErrorThrowableParamsOutsideTransaction() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
    Map<String, String> atts = new HashMap<>();
    atts.put("str", "dude");
    NewRelic.noticeError(new RuntimeException("boom"), atts);
    try {
        // ensure that the errors have different timestamps
        Thread.sleep(5);
    } catch (InterruptedException e) {
    }
    NewRelic.noticeError(new RuntimeException("boom2"), new HashMap<String, String>());
    Collection<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
    Assert.assertEquals("incorrect traced errors count", 2, tracedErrors.size());
    TracedError tracedError = (TracedError) tracedErrors.toArray()[0];
    Assert.assertEquals("error attribute incorrect", "dude", tracedError.getErrorAtts().get("str"));
    Assert.assertEquals("exception class incorrect", "java.lang.RuntimeException", tracedError.getExceptionClass());
    Assert.assertEquals("error message incorrect", "boom", tracedError.getMessage());
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) TracedError(com.newrelic.agent.errors.TracedError) HashMap(java.util.HashMap) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 3 with TracedError

use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorMsgParamsOutsideTransaction.

@Test
public void testNoticeErrorMsgParamsOutsideTransaction() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
    Map<String, String> atts = new HashMap<>();
    atts.put("str", "dude");
    NewRelic.noticeError("outside1", atts);
    try {
        // ensure that the errors have different timestamps
        Thread.sleep(5);
    } catch (InterruptedException e) {
    }
    NewRelic.noticeError("outside2", new HashMap<String, String>());
    Collection<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
    Assert.assertEquals("incorrect traced errors count", 2, tracedErrors.size());
    TracedError tracedError = (TracedError) tracedErrors.toArray()[0];
    Assert.assertEquals("error attribute incorrect", "dude", tracedError.getErrorAtts().get("str"));
    // getExceptionClass on a HTTPTracedError is getMessage
    Assert.assertEquals("exception class incorrect", "outside1", tracedError.getExceptionClass());
    Assert.assertEquals("error message incorrect", "outside1", tracedError.getMessage());
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) TracedError(com.newrelic.agent.errors.TracedError) HashMap(java.util.HashMap) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 4 with TracedError

use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.

the class DeadlockDetectorTest method deadlock.

@Test
public void deadlock() throws InterruptedException {
    ErrorCollectorConfig config = mock(ErrorCollectorConfig.class);
    DeadLockDetector deadlockDetector = new DeadLockDetector(config);
    Thread.sleep(1000);
    ThreadInfo[] deadlockedThreadInfos = deadlockDetector.getDeadlockedThreadInfos();
    int count = 0;
    while (deadlockedThreadInfos.length < 2 && count < 5) {
        count++;
        Thread.sleep(1000);
        deadlockedThreadInfos = deadlockDetector.getDeadlockedThreadInfos();
    }
    assertEquals(2, deadlockedThreadInfos.length);
    assertTrue(deadlockedThreadInfos[0].getStackTrace().length > 0);
    TracedError[] tracedErrors = deadlockDetector.getTracedErrors(Arrays.asList(deadlockedThreadInfos));
    assertEquals(1, tracedErrors.length);
    Map<String, Collection<String>> stackTraces = tracedErrors[0].stackTraces();
    assertTrue(stackTraces.containsKey(deadlockedThreadInfos[0].getThreadName()));
    assertTrue(stackTraces.containsKey(deadlockedThreadInfos[1].getThreadName()));
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) TracedError(com.newrelic.agent.errors.TracedError) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) Collection(java.util.Collection) Test(org.junit.Test)

Example 5 with TracedError

use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeExpectedError.

@Test
public void testNoticeExpectedError() {
    Throwable expectedThrowable = new Throwable("Session timed out. Don't page people");
    com.newrelic.api.agent.NewRelic.noticeError(expectedThrowable, true);
    ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
    List<TracedError> errors = errorService.getAndClearTracedErrors();
    TracedError tracedError = errors.get(0);
    Assert.assertEquals("Session timed out. Don't page people", tracedError.getMessage());
    Assert.assertFalse(tracedError.incrementsErrorMetric());
    Throwable unexpectedThrowable = new Throwable("Surprise surprise, the database is down!");
    com.newrelic.api.agent.NewRelic.noticeError(unexpectedThrowable, false);
    errors = errorService.getAndClearTracedErrors();
    tracedError = errors.get(0);
    Assert.assertEquals("Surprise surprise, the database is down!", tracedError.getMessage());
    Assert.assertTrue(tracedError.incrementsErrorMetric());
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) TracedError(com.newrelic.agent.errors.TracedError) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Aggregations

TracedError (com.newrelic.agent.errors.TracedError)8 Test (org.junit.Test)6 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)4 ErrorService (com.newrelic.agent.errors.ErrorService)4 HashMap (java.util.HashMap)3 Tracer (com.newrelic.agent.tracers.Tracer)2 ThreadInfo (java.lang.management.ThreadInfo)2 MockRPMService (com.newrelic.agent.MockRPMService)1 TracerList (com.newrelic.agent.TracerList)1 TransactionDataList (com.newrelic.agent.TransactionDataList)1 ErrorCollectorConfig (com.newrelic.agent.config.ErrorCollectorConfig)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1