Search in sources :

Example 11 with ErrorCollectorConfig

use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method setupAndVerifyStripExceptionMessage.

private void setupAndVerifyStripExceptionMessage(ConfigEnhancer enhancer, Boolean highSecurity, Boolean stripException, String allowedExceptionClasses, boolean expectedToBeStripped, Throwable exception) throws Exception {
    Map<String, Object> config = createConfig(null, highSecurity, stripException, allowedExceptionClasses);
    enhancer.enhance(config, exception);
    EventTestHelper.createServiceManager(config);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getErrorCollectorConfig(APP_NAME);
    TracedError error = ThrowableError.builder(errorCollectorConfig, APP_NAME, "dude", exception, System.currentTimeMillis()).errorMessageReplacer(new ErrorMessageReplacer(ServiceFactory.getConfigService().getStripExceptionConfig(APP_NAME))).build();
    errorService.reportError(error);
    // Checking ...
    StatsEngineImpl statsEngine = new StatsEngineImpl();
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    if (enhancer.shouldMatch()) {
        // If we supplied a configuration that ignored the error,
        // check that it worked, and we're done here. This verifies
        // the fix for JAVA-2975.
        Assert.assertEquals(0, actualErrors.size());
        return;
    }
    Assert.assertEquals(1, actualErrors.size());
    TracedError tracedError = actualErrors.get(0);
    String expectedMessage = exception.getMessage();
    // - Strip Exceptions On
    if (expectedToBeStripped && (highSecurity != null && highSecurity)) {
        if (stripException == null || stripException) {
            expectedMessage = ErrorMessageReplacer.STRIPPED_EXCEPTION_REPLACEMENT;
        }
    } else if (expectedToBeStripped && (stripException != null && stripException)) {
        expectedMessage = ErrorMessageReplacer.STRIPPED_EXCEPTION_REPLACEMENT;
    }
    Assert.assertEquals("High Security = " + (highSecurity != null ? highSecurity.toString() : "Unset") + ", Strip Exceptions = " + (stripException != null ? stripException.toString() : "Unset") + ", Exceptions to be allowed unstripped = " + (allowedExceptionClasses != null ? allowedExceptionClasses : "Unset"), expectedMessage, tracedError.getMessage());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) MockRPMService(com.newrelic.agent.MockRPMService)

Example 12 with ErrorCollectorConfig

use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method reportError.

@Test
public void reportError() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    EventTestHelper.createServiceManager(config);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    List<TracedError> errors = new ArrayList<>(ErrorServiceImpl.ERROR_LIMIT_PER_REPORTING_PERIOD);
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    for (int i = 0; i < ErrorServiceImpl.ERROR_LIMIT_PER_REPORTING_PERIOD; i++) {
        TracedError error = HttpTracedError.builder(errorCollectorConfig, null, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
        errors.add(error);
        errorService.reportError(error);
    }
    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(errors.size(), actualErrors.size());
    Assert.assertTrue(actualErrors.containsAll(errors));
    error = HttpTracedError.builder(errorCollectorConfig, null, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
    errorService.reportError(error);
    actualErrors = errorService.getAndClearTracedErrors();
    Assert.assertEquals(1, actualErrors.size());
    Assert.assertEquals(error, actualErrors.get(0));
    Assert.assertEquals(ErrorServiceImpl.ERROR_LIMIT_PER_REPORTING_PERIOD + 2, errorService.errorCountThisHarvest.get());
}
Also used : ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with ErrorCollectorConfig

use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.

the class TracedErrorTest method attributesNull.

@Test
@SuppressWarnings("unchecked")
public void attributesNull() throws Exception {
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").prefixedAttributes(null).userAttributes(null).agentAttributes(null).errorAttributes(null).intrinsicAttributes(null).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> agentAttributes = (Map<String, Object>) params.get("agentAttributes");
    assertEquals("/dude", agentAttributes.get("request.uri"));
    Map<String, Object> intrinsicsParam = (Map<String, Object>) params.get("intrinsics");
    assertEquals(false, intrinsicsParam.get("error.expected"));
}
Also used : 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)

Example 14 with ErrorCollectorConfig

use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.

the class TracedErrorTest method httpIntrinsicAttributes.

@Test
@SuppressWarnings("unchecked")
public void httpIntrinsicAttributes() throws Exception {
    Map<String, Object> agentAttributes = new HashMap<>();
    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").agentAttributes(agentAttributes).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"));
    assertNotNull(params.get("intrinsics"));
    Map<String, Object> serializedAgentAtts = (Map<String, Object>) params.get("agentAttributes");
    assertEquals("/dude", serializedAgentAtts.get("request.uri"));
    Map<String, Object> atts = (Map<String, Object>) params.get("intrinsics");
    assertEquals(2, atts.size());
    assertEquals("value5", atts.get("key5"));
    assertEquals(false, atts.get("error.expected"));
}
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)

Example 15 with ErrorCollectorConfig

use of com.newrelic.agent.config.ErrorCollectorConfig in project newrelic-java-agent by newrelic.

the class TracedErrorTest method httpErrorAttributes.

@Test
@SuppressWarnings("unchecked")
public void httpErrorAttributes() throws Exception {
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Map<String, String>> prefixes = new HashMap<>();
    prefixes.put("hello.", requestParams);
    Map<String, Object> agentAttributes = new HashMap<>();
    Map<String, String> errorParams = new HashMap<>();
    errorParams.put("key4", "value4");
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").prefixedAttributes(prefixes).agentAttributes(agentAttributes).errorAttributes(errorParams).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(2, atts.size());
    assertEquals("value1", atts.get("hello.key1"));
    assertEquals("/dude", atts.get("request.uri"));
    atts = (Map<String, Object>) params.get("userAttributes");
    assertEquals(1, atts.size());
    assertEquals("value4", atts.get("key4"));
    Map<String, Object> intrinsicsParam = (Map<String, Object>) params.get("intrinsics");
    assertEquals(false, intrinsicsParam.get("error.expected"));
}
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