Search in sources :

Example 26 with ErrorCollectorConfig

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

Example 27 with ErrorCollectorConfig

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

Example 28 with ErrorCollectorConfig

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

Example 29 with ErrorCollectorConfig

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

Example 30 with ErrorCollectorConfig

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));
}
Also used : HashMap(java.util.HashMap) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) 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