use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorAnalyzerImplTest method ignoredThrowableFollowsConfig.
@Test
public void ignoredThrowableFollowsConfig() {
ErrorCollectorConfig config = new TestErrorCollectorConfig().setIgnoreErrors(new IgnoreErrorConfigImpl(MyThrowable.class.getName(), null), new IgnoreErrorConfigImpl(RuntimeException.class.getName(), "ignore_token"));
ErrorAnalyzer target = new ErrorAnalyzerImpl(config);
assertTrue(target.isIgnoredThrowable(new MyThrowable("message")));
assertTrue(target.isIgnoredThrowable(new MyThrowable(null)));
assertTrue(target.isIgnoredThrowable(new RuntimeException("ignore_token")));
assertFalse(target.isIgnoredThrowable(new RuntimeException("not ignored")));
assertFalse(target.isIgnoredThrowable(new RuntimeException((String) null)));
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorAnalyzerImplTest method ignoreStatusCodeOrThrowable.
@Test
public void ignoreStatusCodeOrThrowable() {
ErrorCollectorConfig config = new TestErrorCollectorConfig().setIgnoreStatusCodes(HTTP_BAD_REQUEST, HTTP_ACCEPTED).setIgnoreErrors(new IgnoreErrorConfigImpl(MyThrowable.class.getName(), null), new IgnoreErrorConfigImpl(RuntimeException.class.getName(), "ignore_token"));
ErrorAnalyzer target = new ErrorAnalyzerImpl(config);
// neither status nor throwable are ignored.
assertFalse(target.isIgnoredError(HTTP_OK, null));
assertFalse(target.isIgnoredError(HTTP_OK, new RuntimeException("not ignored")));
assertFalse(target.isIgnoredError(HTTP_OK, new RuntimeException((String) null)));
// only the throwable is ignored.
assertTrue(target.isIgnoredError(HTTP_OK, new MyThrowable("message")));
assertTrue(target.isIgnoredError(HTTP_OK, new MyThrowable(null)));
assertTrue(target.isIgnoredError(HTTP_OK, new RuntimeException("ignore_token")));
// only the status is ignored
assertTrue(target.isIgnoredError(HTTP_BAD_REQUEST, null));
assertTrue(target.isIgnoredError(HTTP_BAD_REQUEST, new RuntimeException("not ignored")));
assertTrue(target.isIgnoredError(HTTP_BAD_REQUEST, new RuntimeException((String) null)));
// both status and throwable are ignored
assertTrue(target.isIgnoredError(HTTP_BAD_REQUEST, new MyThrowable("message")));
assertTrue(target.isIgnoredError(HTTP_BAD_REQUEST, new MyThrowable(null)));
assertTrue(target.isIgnoredError(HTTP_BAD_REQUEST, new RuntimeException("ignore_token")));
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method createTransactionData.
private TransactionData createTransactionData(boolean isWebTransaction, int responseStatus, Throwable throwable, boolean expectedError, Map<String, String> requestParams, Map<String, Object> userParams, Map<String, Object> agentParams, Map<String, Object> errorParams, Map<String, Object> intrinsics) {
AgentConfig iAgentConfig = mock(AgentConfig.class);
ErrorCollectorConfig errorCollectorConfig = mock(ErrorCollectorConfig.class);
when(iAgentConfig.getErrorCollectorConfig()).thenReturn(errorCollectorConfig);
MockDispatcher dispatcher = new MockDispatcher();
dispatcher.setWebTransaction(isWebTransaction);
Tracer rootTracer = new MockDispatcherTracer();
String frontendMetricName = isWebTransaction ? "WebTransaction/Uri/dude" : "OtherTransaction/Custom/dude";
return new TransactionDataTestBuilder(APP_NAME, iAgentConfig, rootTracer).setDispatcher(dispatcher).setFrontendMetricName(frontendMetricName).setThrowable(throwable).setExpectedError(expectedError).setRequestUri("/dude").setResponseStatus(responseStatus).setStatusMessage("").setRequestParams(requestParams).setAgentParams(agentParams).setUserParams(userParams).setErrorParams(errorParams).setIntrinsics(intrinsics).build();
}
use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method notEnabled.
@Test
public void notEnabled() 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, false);
errorService.refreshErrorCollectorConfig(AgentConfigFactory.createAgentConfig(configMap, null, null));
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = HttpTracedError.builder(errorCollectorConfig, APP_NAME, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
errorService.reportError(error);
List<TracedError> actualErrors = errorService.getAndClearTracedErrors();
Assert.assertEquals(0, 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 harvest.
@Test
public void harvest() throws Exception {
Map<String, Object> config = createConfig("java.lang.Exception");
EventTestHelper.createServiceManager(config);
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
rpmService.setIsConnected(false);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = HttpTracedError.builder(errorCollectorConfig, APP_NAME, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
errorService.reportError(error);
StatsService spy = spy(new StatsServiceImpl());
StatsEngine statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
Assert.assertEquals(0, actualErrors.size());
Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
rpmService.setIsConnected(true);
actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
Assert.assertEquals(1, actualErrors.size());
Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
}
Aggregations