Search in sources :

Example 16 with ErrorCollectorConfig

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

the class TracedErrorTest method httpAttributes.

@Test
@SuppressWarnings("unchecked")
public void httpAttributes() throws Exception {
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Map<String, String>> prefixes = new HashMap<>();
    prefixes.put("request.parameters.", requestParams);
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key2", 2L);
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key3", "value3");
    Map<String, String> errorParams = new HashMap<>();
    errorParams.put("key4", "value4");
    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").prefixedAttributes(prefixes).userAttributes(userParams).agentAttributes(agentParams).errorAttributes(errorParams).intrinsicAttributes(intrinsics).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(2L, atts.get("key2"));
    assertEquals("/dude", atts.get("request.uri"));
    atts = (Map<String, Object>) params.get("userAttributes");
    assertEquals(2, atts.size());
    assertEquals("value4", atts.get("key4"));
    assertEquals("value3", atts.get("key3"));
    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 17 with ErrorCollectorConfig

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

the class TracedErrorTest method attributesEmpty.

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

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

the class DeadlockDetectorTest method deadlock.

@Test
public void deadlock() throws InterruptedException {
    ErrorCollectorConfig config = mock(ErrorCollectorConfig.class);
    DeadLockDetector deadlockDetector = new DeadLockDetector(config);
    Thread.sleep(1000);
    ThreadInfo[] deadlockedThreadInfos = deadlockDetector.getDeadlockedThreadInfos();
    int count = 0;
    while (deadlockedThreadInfos.length < 2 && count < 5) {
        count++;
        Thread.sleep(1000);
        deadlockedThreadInfos = deadlockDetector.getDeadlockedThreadInfos();
    }
    assertEquals(2, deadlockedThreadInfos.length);
    assertTrue(deadlockedThreadInfos[0].getStackTrace().length > 0);
    TracedError[] tracedErrors = deadlockDetector.getTracedErrors(Arrays.asList(deadlockedThreadInfos));
    assertEquals(1, tracedErrors.length);
    Map<String, Collection<String>> stackTraces = tracedErrors[0].stackTraces();
    assertTrue(stackTraces.containsKey(deadlockedThreadInfos[0].getThreadName()));
    assertTrue(stackTraces.containsKey(deadlockedThreadInfos[1].getThreadName()));
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) TracedError(com.newrelic.agent.errors.TracedError) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) Collection(java.util.Collection) Test(org.junit.Test)

Example 19 with ErrorCollectorConfig

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

the class RPMServiceTest method doTestTracedErrors.

private void doTestTracedErrors() throws Exception {
    ErrorCollectorConfig config = mock(ErrorCollectorConfig.class);
    List<String> appNames = new ArrayList<>(1);
    appNames.add("MyApplication");
    RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
    svc.launch();
    final ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(Thread.currentThread().getId(), 100);
    Map<String, StackTraceElement[]> stackTraceMap = new HashMap<String, StackTraceElement[]>() {

        private static final long serialVersionUID = 1L;

        {
            put("dude", threadInfo.getStackTrace());
            put("dude1", threadInfo.getStackTrace());
        }
    };
    Map<String, String> parameters = Collections.emptyMap();
    svc.getErrorService().reportErrors(DeadlockTraceError.builder(config, null, System.currentTimeMillis()).threadInfoAndStackTrace(threadInfo, stackTraceMap).errorAttributes(parameters).build(), ThrowableError.builder(config, null, "", new Exception("Test"), System.currentTimeMillis()).build());
    svc.getErrorService().getAndClearTracedErrors();
    svc.shutdown();
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) HashMap(java.util.HashMap) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) ArrayList(java.util.ArrayList) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 20 with ErrorCollectorConfig

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

the class ErrorAnalyzerImplTest method expectedThrowableFollowsAnyCause.

@Test
public void expectedThrowableFollowsAnyCause() {
    ErrorCollectorConfig config = new TestErrorCollectorConfig().setExpectedErrors(new ExpectedErrorConfigImpl(MyThrowable.class.getName(), null));
    ErrorAnalyzer target = new ErrorAnalyzerImpl(config);
    assertTrue(target.isExpectedError(HTTP_OK, wrap(new MyThrowable("message"))));
    assertTrue(target.isExpectedError(HTTP_OK, wrap(new Exception("other", new MyThrowable("message")))));
    assertFalse(target.isExpectedError(HTTP_OK, wrap(new Exception("other"))));
}
Also used : ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) ExpectedErrorConfigImpl(com.newrelic.agent.config.ExpectedErrorConfigImpl) 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