use of com.newrelic.agent.config.StripExceptionConfigImpl in project newrelic-java-agent by newrelic.
the class TracedErrorTest method nestedExceptionsStripSome.
@Test
public void nestedExceptionsStripSome() {
Exception nested2 = new NullPointerException("Null Pointer Exception should be stripped");
Exception nested1 = new IOException("IO Exception should not be stripped", nested2);
Exception top = new RuntimeException("RuntimeException should be stripped", nested1);
Exception suppressed1 = new IllegalStateException("IllegalStateException should be stripped");
Exception suppressed2 = new IllegalArgumentException("IllegalArgumentException should not be stripped");
top.addSuppressed(suppressed1);
nested1.addSuppressed(suppressed2);
ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
TracedError error = ThrowableError.builder(errorCollectorConfig, null, null, top, System.currentTimeMillis()).errorMessageReplacer(new ErrorMessageReplacer(new StripExceptionConfigImpl(true, Sets.newSet("java.io.IOException", IllegalArgumentException.class.getName())))).build();
assertEquals(error.getMessage(), "Message removed by New Relic 'strip_exception_messages' setting");
Collection<String> stackTrace = error.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(suppressed1.toString()));
next = findNextCausedBy(it);
assertTrue(next, next.contains("caused by java.io.IOException: IO Exception should not be stripped"));
next = findNextContaining(it, "Suppressed:");
assertTrue(next, next.contains("Suppressed: java.lang.IllegalArgumentException: IllegalArgumentException should not be stripped"));
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()));
}
Aggregations