Search in sources :

Example 31 with ErrorCollectorConfig

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

Example 32 with ErrorCollectorConfig

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

the class TracedErrorTest method httpError.

@Test
public void httpError() throws Exception {
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
    assertNull(error.stackTrace());
    assertEquals("HttpClientError 403", error.getMessage());
    assertEquals("HttpClientError 403", error.getExceptionClass());
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(error);
    assertNotNull(serializedError);
    assertEquals(error.getMessage(), serializedError.get(2));
// assertNull(serializedError.get("s"))
}
Also used : ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test)

Example 33 with ErrorCollectorConfig

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

the class TracedErrorTest method throwableError.

@Test
public void throwableError() throws Exception {
    String msg = "Oh dude!";
    Error e = new UnsupportedClassVersionError(msg);
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    TracedError error = ThrowableError.builder(errorCollectorConfig, null, null, e, System.currentTimeMillis()).build();
    assertNotNull(error.stackTrace());
    assertEquals(msg, error.getMessage());
    assertEquals(UnsupportedClassVersionError.class.getName(), error.getExceptionClass());
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(error);
    assertNotNull(serializedError);
    JSONObject params = (JSONObject) serializedError.get(4);
    assertNotNull(params.get("stack_trace"));
}
Also used : JSONObject(org.json.simple.JSONObject) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test)

Example 34 with ErrorCollectorConfig

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

the class TracedErrorTest method nestedExceptionsNoStripping.

@Test
public void nestedExceptionsNoStripping() throws Exception {
    Exception nested2 = new NullPointerException("NPE");
    StackTraceElement stack1 = new StackTraceElement("Class1", "Method1", "Class1.java", 1);
    StackTraceElement stack2 = new StackTraceElement("Class2", "Method2", "Class2.java", 2);
    StackTraceElement stack3 = new StackTraceElement("Class3", "Method3", "Class3.java", 3);
    StackTraceElement[] stack_123 = new StackTraceElement[] { stack1, stack2, stack3 };
    nested2.setStackTrace(stack_123);
    Exception nested1 = new IOException("IO", nested2);
    StackTraceElement stack4 = new StackTraceElement("Class4", "Method4", "Class4.java", 4);
    StackTraceElement stack5 = new StackTraceElement("Class5", "Method5", "Class5.java", 5);
    StackTraceElement stack6 = new StackTraceElement("Class6", "Method6", "Class6.java", 6);
    StackTraceElement[] stack_456 = new StackTraceElement[] { stack4, stack5, stack6 };
    nested1.setStackTrace(stack_456);
    Exception top = new RuntimeException("RTE", nested1);
    StackTraceElement stack7 = new StackTraceElement("Class7", "Method7", "Class7.java", 7);
    StackTraceElement stack8 = new StackTraceElement("Class8", "Method8", "Class8.java", 8);
    StackTraceElement stack9 = new StackTraceElement("Class9", "Method9", "Class9.java", 9);
    StackTraceElement[] stack_789 = new StackTraceElement[] { stack7, stack8, stack9 };
    top.setStackTrace(stack_789);
    Exception suppressed1 = new IllegalStateException("ISE");
    StackTraceElement stack10 = new StackTraceElement("Class10", "Method10", "Class10.java", 10);
    StackTraceElement stack11 = new StackTraceElement("Class11", "Method11", "Class11.java", 11);
    StackTraceElement stack12 = new StackTraceElement("Class12", "Method12", "Class12.java", 12);
    suppressed1.setStackTrace(new StackTraceElement[] { stack10, stack11, stack12 });
    top.addSuppressed(suppressed1);
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    TracedError error = ThrowableError.builder(errorCollectorConfig, null, null, top, System.currentTimeMillis()).build();
    Collection<String> stackTrace = error.stackTrace();
    assertNotNull(stackTrace);
    assertEquals(17, stackTrace.size());
    Iterator<String> it = stackTrace.iterator();
    assertTrue(it.next().contains("7"));
    assertTrue(it.next().contains("8"));
    assertTrue(it.next().contains("9"));
    String next = it.next();
    assertTrue(next.contains("Suppressed:"));
    assertTrue(next.contains(suppressed1.toString()));
    assertTrue(it.next().contains("10"));
    assertTrue(it.next().contains("11"));
    assertTrue(it.next().contains("12"));
    assertEquals("", it.next().trim());
    next = it.next();
    assertTrue(next.contains("caused by"));
    assertTrue(next.contains(nested1.toString()));
    assertTrue(it.next().contains("4"));
    assertTrue(it.next().contains("5"));
    assertTrue(it.next().contains("6"));
    assertEquals("", it.next().trim());
    next = it.next();
    assertTrue(next.contains("caused by"));
    assertTrue(next.contains(nested2.toString()));
    assertTrue(it.next().contains("1"));
    assertTrue(it.next().contains("2"));
    assertTrue(it.next().contains("3"));
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(error);
    assertNotNull(serializedError);
    JSONObject params = (JSONObject) serializedError.get(4);
    assertNotNull(params.get("stack_trace"));
}
Also used : JSONArray(org.json.simple.JSONArray) IOException(java.io.IOException) IOException(java.io.IOException) JSONObject(org.json.simple.JSONObject) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) 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