use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method enabled.
@Test
public void enabled() throws Exception {
Map<String, Object> config = createConfig("java.lang.Exception");
EventTestHelper.createServiceManager(config);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
Map<String, Object> configMap = new HashMap<>();
Map<String, Object> errorMap = new HashMap<>();
configMap.put(AgentConfigImpl.ERROR_COLLECTOR, errorMap);
errorMap.put(ErrorCollectorConfigImpl.ENABLED, true);
errorMap.put(ErrorCollectorConfigImpl.COLLECT_ERRORS, true);
errorService.refreshErrorCollectorConfig(AgentConfigFactory.createAgentConfig(configMap, null, null));
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = HttpTracedError.builder(errorCollectorConfig, null, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
errorService.reportError(error);
List<TracedError> actualErrors = errorService.getAndClearTracedErrors();
Assert.assertEquals(1, actualErrors.size());
Assert.assertEquals(1, errorService.errorCountThisHarvest.get());
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method ignored.
@Test
public void ignored() throws Exception {
Map<String, Object> config = createConfig("java.lang.Exception");
EventTestHelper.createServiceManager(config);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getErrorCollectorConfig(APP_NAME);
TracedError error = ThrowableError.builder(errorCollectorConfig, APP_NAME, "dude", new Exception(), System.currentTimeMillis()).build();
errorService.reportError(error);
List<TracedError> actualErrors = errorService.getAndClearTracedErrors();
Assert.assertEquals(0, actualErrors.size());
Assert.assertEquals(0, errorService.errorCountThisHarvest.get());
Map<String, Object> configMap = new HashMap<>();
Map<String, Object> errorMap = new HashMap<>();
configMap.put(AgentConfigImpl.ERROR_COLLECTOR, errorMap);
errorMap.put(ErrorCollectorConfigImpl.ENABLED, true);
errorMap.put(ErrorCollectorConfigImpl.COLLECT_ERRORS, true);
errorMap.put(ErrorCollectorConfigImpl.IGNORE_ERRORS, "java.lang.Exception");
errorService.refreshErrorCollectorConfig(AgentConfigFactory.createAgentConfig(configMap, null, null));
errorService.reportError(error);
actualErrors = errorService.getAndClearTracedErrors();
Assert.assertEquals(0, actualErrors.size());
Assert.assertEquals(0, errorService.errorCountThisHarvest.get());
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method testAppNameFiltering.
@Test
public void testAppNameFiltering() throws Exception {
Map<String, Object> config = createConfig("java.lang.Exception");
EventTestHelper.createServiceManager(config);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
Map<String, Object> configMap = new HashMap<>();
Map<String, Object> errorMap = new HashMap<>();
configMap.put(AgentConfigImpl.ERROR_COLLECTOR, errorMap);
errorMap.put(ErrorCollectorConfigImpl.ENABLED, true);
errorMap.put(ErrorCollectorConfigImpl.COLLECT_ERRORS, true);
errorService.refreshErrorCollectorConfig(AgentConfigFactory.createAgentConfig(configMap, null, null));
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = HttpTracedError.builder(errorCollectorConfig, null, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
errorService.reportError(error);
errorService.harvestTracedErrors("some_other_app", ServiceFactory.getStatsService().getStatsEngineForHarvest("some_other_app"));
List<TracedError> actualErrors = errorService.getAndClearTracedErrors();
// If the harvest above this worked, there should be no traced. But the harvest should not capture anything since it is from a different app name
Assert.assertEquals(1, actualErrors.size());
Assert.assertEquals(1, errorService.errorCountThisHarvest.get());
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class TracedErrorTest method nestedExceptionsStripAll.
@Test
public void nestedExceptionsStripAll() {
Exception nested2 = new NullPointerException("Null Pointer Exception should be stripped");
Exception nested1 = new IOException("IO Exception should be stripped", nested2);
Exception top = new RuntimeException("RuntimeException should be stripped", nested1);
Exception suppressed = new IllegalStateException("IllegalStateException should be stripped");
top.addSuppressed(suppressed);
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = ThrowableError.builder(errorCollectorConfig, null, null, top, System.currentTimeMillis()).errorMessageReplacer(new ErrorMessageReplacer(new StripExceptionConfigImpl(true, Collections.<String>emptySet()))).build();
assertEquals(error.getMessage(), "Message removed by New Relic 'strip_exception_messages' setting");
Collection<String> stackTrace = error.stackTrace();
assertNotNull(stackTrace);
Iterator<String> it = stackTrace.iterator();
String next = findNextContaining(it, "Suppressed:");
assertTrue(next, next.contains("Suppressed: java.lang.IllegalStateException: Message removed by New Relic 'strip_exception_messages' setting"));
assertFalse(next.contains(suppressed.toString()));
next = findNextCausedBy(it);
assertTrue(next, next.contains("caused by java.io.IOException: Message removed by New Relic 'strip_exception_messages' setting"));
assertFalse(next.contains(nested1.toString()));
next = findNextCausedBy(it);
assertTrue(next, next.contains("caused by java.lang.NullPointerException: Message removed by New Relic 'strip_exception_messages' setting"));
assertFalse(next.contains(nested2.toString()));
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class TracedErrorTest method testerrorWithTimeout.
@SuppressWarnings("unchecked")
@Test
public void testerrorWithTimeout() throws Exception {
Throwable throwable = new Throwable();
Map<String, Object> intrinsics = new HashMap<>();
intrinsics.put("nr.timeoutCause", "token");
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = ThrowableError.builder(errorCollectorConfig, "appName", "metricName", throwable, 100).requestUri("requestUri").intrinsicAttributes(intrinsics).build();
JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(error);
Map<String, Object> attributes = (Map<String, Object>) serializedError.get(4);
Map<String, Object> intrinsicAtt = (Map<String, Object>) attributes.get("intrinsics");
assertNotNull(intrinsicAtt.get(AttributeNames.TIMEOUT_CAUSE));
}
Aggregations