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"));
}
}
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());
}
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());
}
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()));
}
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());
}
Aggregations