use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.
the class ApiTest method testNoticeErrorOutsideTransaction.
@Test
public void testNoticeErrorOutsideTransaction() throws Exception {
ApiTestHelper.mockOutServiceManager();
ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
NewRelic.noticeError(new RuntimeException("boom"));
try {
// ensure that the ThrowableErrors have different timestamps
Thread.sleep(5);
} catch (InterruptedException e) {
}
NewRelic.noticeError(new RuntimeException("boom2"));
Collection<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
Assert.assertEquals("incorrect traced errors count: " + tracedErrors.toString(), 2, tracedErrors.size());
TracedError tracedError = (TracedError) tracedErrors.toArray()[0];
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 SpanParentTest method testErrorAttributes.
@Test
public void testErrorAttributes() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
Header actualHeader = txnStarter(true);
try {
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
Collection<Tracer> tracers = transactionList.get(0).getTracers();
Tracer tracer = ((TracerList) tracers).get(0);
String expectedGuid = tracer.getGuid();
String actualGuid = findGuid(actualHeader.getValue());
Assert.assertEquals(expectedGuid, actualGuid);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
List<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
assertEquals(1, tracedErrors.size());
TracedError errorTrace = tracedErrors.get(0);
Map<String, ?> errorAtts = errorTrace.getIntrinsicAtts();
Assert.assertNotNull(errorAtts.get("traceId"));
Assert.assertNotNull(errorAtts.get("guid"));
Assert.assertNotNull(errorAtts.get("priority"));
Assert.assertNotNull(errorAtts.get("sampled"));
} finally {
holder.close();
}
}
use of com.newrelic.agent.errors.TracedError in project newrelic-java-agent by newrelic.
the class DeadLockDetector method getTracedErrors.
/**
* Returns a list of traced errors for the given deadlocked threads. This list should be smaller than the original
* list of threads - one error is created for each pair of deadlocked threads, and the error contains a stack trace
* for each thread.
*/
TracedError[] getTracedErrors(List<ThreadInfo> threadInfos) {
Map<Long, ThreadInfo> idToThreads = new HashMap<>();
for (ThreadInfo thread : threadInfos) {
idToThreads.put(thread.getThreadId(), thread);
}
List<TracedError> errors = new ArrayList<>();
Set<Long> skipIds = new HashSet<>();
StringBuffer deadlockMsg = new StringBuffer();
for (ThreadInfo thread : threadInfos) {
if (!skipIds.contains(thread.getThreadId())) {
long otherId = thread.getLockOwnerId();
skipIds.add(otherId);
ThreadInfo otherThread = idToThreads.get(otherId);
// four to preserve memory and not cause a new map to be created
Map<String, String> parameters = Maps.newHashMapWithExpectedSize(4);
parameters.put(AttributeNames.THREAD_NAME, thread.getThreadName());
Map<String, StackTraceElement[]> stackTraces = new HashMap<>();
stackTraces.put(thread.getThreadName(), thread.getStackTrace());
if (otherThread != null) {
parameters.put(AttributeNames.LOCK_THREAD_NAME, otherThread.getThreadName());
stackTraces.put(otherThread.getThreadName(), otherThread.getStackTrace());
}
if (!errors.isEmpty()) {
deadlockMsg.append(", ");
}
deadlockMsg.append(thread.toString());
errors.add(DeadlockTraceError.builder(errorCollectorConfig, null, System.currentTimeMillis()).threadInfoAndStackTrace(thread, stackTraces).errorAttributes(parameters).build());
}
}
Agent.LOG.log(Level.FINER, "There are {0} deadlocked thread(s): [{1}]", errors.size(), deadlockMsg);
return errors.toArray(new TracedError[0]);
}
Aggregations