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());
}
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());
}
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"));
}
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"));
}
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"));
}
Aggregations