use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class TracedErrorTest method httpAttributes.
@Test
@SuppressWarnings("unchecked")
public void httpAttributes() throws Exception {
Map<String, String> requestParams = new HashMap<>();
requestParams.put("key1", "value1");
Map<String, Map<String, String>> prefixes = new HashMap<>();
prefixes.put("request.parameters.", requestParams);
Map<String, Object> agentParams = new HashMap<>();
agentParams.put("key2", 2L);
Map<String, Object> userParams = new HashMap<>();
userParams.put("key3", "value3");
Map<String, String> errorParams = new HashMap<>();
errorParams.put("key4", "value4");
Map<String, Object> intrinsics = new HashMap<>();
intrinsics.put("key5", "value5");
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").prefixedAttributes(prefixes).userAttributes(userParams).agentAttributes(agentParams).errorAttributes(errorParams).intrinsicAttributes(intrinsics).build();
JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(error);
assertNotNull(serializedError);
Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
assertEquals(4, params.size());
assertNotNull(params.get("stack_traces"));
assertNotNull(params.get("agentAttributes"));
assertNotNull(params.get("userAttributes"));
assertNotNull(params.get("intrinsics"));
Map<String, Object> atts = (Map<String, Object>) params.get("agentAttributes");
assertEquals(2L, atts.get("key2"));
assertEquals("/dude", atts.get("request.uri"));
atts = (Map<String, Object>) params.get("userAttributes");
assertEquals(2, atts.size());
assertEquals("value4", atts.get("key4"));
assertEquals("value3", atts.get("key3"));
atts = (Map<String, Object>) params.get("intrinsics");
assertEquals(2, atts.size());
assertEquals("value5", atts.get("key5"));
assertEquals(false, atts.get("error.expected"));
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class TracedErrorTest method attributesEmpty.
@Test
@SuppressWarnings("unchecked")
public void attributesEmpty() throws Exception {
Map<String, Map<String, String>> prefixes = new HashMap<>();
Map<String, Object> agentParams = new HashMap<>();
Map<String, Object> userParams = new HashMap<>();
Map<String, String> errorParams = new HashMap<>();
Map<String, Object> intrinsics = new HashMap<>();
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").prefixedAttributes(prefixes).userAttributes(userParams).agentAttributes(agentParams).errorAttributes(errorParams).intrinsicAttributes(intrinsics).build();
JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(error);
assertNotNull(serializedError);
Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
assertEquals(3, params.size());
assertNotNull(params.get("stack_traces"));
Map<String, Object> intrinsicsParam = (Map<String, Object>) params.get("intrinsics");
assertEquals(false, intrinsicsParam.get("error.expected"));
Map<String, Object> serializedAgentAtts = (Map<String, Object>) params.get("agentAttributes");
assertEquals("/dude", serializedAgentAtts.get("request.uri"));
}
use of com.newrelic.agent.config.ErrorCollectorConfig 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.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doTestTracedErrors.
private void doTestTracedErrors() throws Exception {
ErrorCollectorConfig config = mock(ErrorCollectorConfig.class);
List<String> appNames = new ArrayList<>(1);
appNames.add("MyApplication");
RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
svc.launch();
final ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(Thread.currentThread().getId(), 100);
Map<String, StackTraceElement[]> stackTraceMap = new HashMap<String, StackTraceElement[]>() {
private static final long serialVersionUID = 1L;
{
put("dude", threadInfo.getStackTrace());
put("dude1", threadInfo.getStackTrace());
}
};
Map<String, String> parameters = Collections.emptyMap();
svc.getErrorService().reportErrors(DeadlockTraceError.builder(config, null, System.currentTimeMillis()).threadInfoAndStackTrace(threadInfo, stackTraceMap).errorAttributes(parameters).build(), ThrowableError.builder(config, null, "", new Exception("Test"), System.currentTimeMillis()).build());
svc.getErrorService().getAndClearTracedErrors();
svc.shutdown();
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorAnalyzerImplTest method expectedThrowableFollowsAnyCause.
@Test
public void expectedThrowableFollowsAnyCause() {
ErrorCollectorConfig config = new TestErrorCollectorConfig().setExpectedErrors(new ExpectedErrorConfigImpl(MyThrowable.class.getName(), null));
ErrorAnalyzer target = new ErrorAnalyzerImpl(config);
assertTrue(target.isExpectedError(HTTP_OK, wrap(new MyThrowable("message"))));
assertTrue(target.isExpectedError(HTTP_OK, wrap(new Exception("other", new MyThrowable("message")))));
assertFalse(target.isExpectedError(HTTP_OK, wrap(new Exception("other"))));
}
Aggregations