Search in sources :

Example 6 with ErrorCollectorConfig

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)));
}
Also used : ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) IgnoreErrorConfigImpl(com.newrelic.agent.config.IgnoreErrorConfigImpl) Test(org.junit.Test)

Example 7 with ErrorCollectorConfig

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")));
}
Also used : ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) IgnoreErrorConfigImpl(com.newrelic.agent.config.IgnoreErrorConfigImpl) Test(org.junit.Test)

Example 8 with ErrorCollectorConfig

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();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) Tracer(com.newrelic.agent.tracers.Tracer) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) MockDispatcher(com.newrelic.agent.MockDispatcher) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder)

Example 9 with ErrorCollectorConfig

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());
}
Also used : HashMap(java.util.HashMap) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) Test(org.junit.Test)

Example 10 with ErrorCollectorConfig

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());
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

ErrorCollectorConfig (com.newrelic.agent.config.ErrorCollectorConfig)34 Test (org.junit.Test)30 HashMap (java.util.HashMap)12 JSONArray (org.json.simple.JSONArray)9 JSONObject (org.json.simple.JSONObject)8 Map (java.util.Map)6 ExpectedErrorConfigImpl (com.newrelic.agent.config.ExpectedErrorConfigImpl)3 IgnoreErrorConfigImpl (com.newrelic.agent.config.IgnoreErrorConfigImpl)3 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)3 IOException (java.io.IOException)3 MockRPMService (com.newrelic.agent.MockRPMService)2 StripExceptionConfigImpl (com.newrelic.agent.config.StripExceptionConfigImpl)2 ThreadInfo (java.lang.management.ThreadInfo)2 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MockDispatcher (com.newrelic.agent.MockDispatcher)1 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)1 MockServiceManager (com.newrelic.agent.MockServiceManager)1 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1