Search in sources :

Example 46 with StatsEngineImpl

use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.

the class DataCollectionConfigCrossAgentTest method createAndVerifyErrorTrace.

private void createAndVerifyErrorTrace(Long expectedCount, Long expectedEndpointCount) {
    ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
    rpmService.setErrorService(errorService);
    long eventsToCreate = 1;
    if (expectedCount > 1) {
        eventsToCreate = expectedCount;
    }
    for (long i = 0; i < eventsToCreate; i++) {
        ThrowableError error = ThrowableError.builder(errorService.getErrorCollectorConfig(), APP_NAME, "metric", new Throwable(), System.currentTimeMillis()).build();
        errorService.reportError(error);
    }
    // Verify that the correct number of traces were stored in the reservoir
    assertEquals(expectedCount.intValue(), errorService.getTracedErrorsCount());
    // Verify that we sent (or didn't send) the appropriate traces
    errorService.harvestTracedErrors(APP_NAME, new StatsEngineImpl());
    int errorTracesSeen = rpmService.getErrorTracesSeen();
    assertEquals(expectedEndpointCount.intValue(), errorTracesSeen);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) ThrowableError(com.newrelic.agent.errors.ThrowableError)

Example 47 with StatsEngineImpl

use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method userParametersEnabledRequestDisabled.

@SuppressWarnings("unchecked")
@Test
public void userParametersEnabledRequestDisabled() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    setConfigAttributes(config, true, false);
    EventTestHelper.createServiceManager(config);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key2", 2L);
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key3", "value3");
    Map<String, Object> errorParams = new HashMap<>();
    errorParams.put("key4", "value4");
    Map<String, Object> intrinsics = new HashMap<>();
    intrinsics.put("key5", "value5");
    intrinsics.put("key6", 7.77);
    intrinsics.put("key7", 18L);
    TransactionData data = createTransactionData(true, 0, error, false, requestParams, userParams, agentParams, errorParams, intrinsics);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, new StatsEngineImpl());
    Assert.assertEquals(1, actualErrors.size());
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(actualErrors.get(0));
    Assert.assertNotNull(serializedError);
    Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
    Assert.assertEquals(4, params.size());
    Assert.assertNotNull(params.get("stack_trace"));
    Assert.assertNotNull(params.get("intrinsics"));
    Assert.assertNotNull(params.get("agentAttributes"));
    Assert.assertNotNull(params.get("userAttributes"));
    Map<String, Object> actual = (Map<String, Object>) params.get("intrinsics");
    Assert.assertEquals(8, actual.size());
    Assert.assertEquals("value5", actual.get("key5"));
    Assert.assertEquals(7.77, (Double) actual.get("key6"), .001);
    Assert.assertEquals(18L, actual.get("key7"));
    Assert.assertEquals(false, actual.get("error.expected"));
    actual = (Map<String, Object>) params.get("agentAttributes");
    Assert.assertEquals(2, actual.size());
    Assert.assertEquals(2L, actual.get("key2"));
    Assert.assertEquals("/dude", actual.get("request.uri"));
    actual = (Map<String, Object>) params.get("userAttributes");
    Assert.assertEquals(2, actual.size());
    Assert.assertEquals("value3", actual.get("key3"));
    Assert.assertEquals("value4", actual.get("key4"));
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionData(com.newrelic.agent.TransactionData) HashMap(java.util.HashMap) Map(java.util.Map) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 48 with StatsEngineImpl

use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method userParametersEnabled.

@SuppressWarnings("unchecked")
@Test
public void userParametersEnabled() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    setConfigAttributes(config, true, true);
    EventTestHelper.createServiceManager(config);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key2", 2L);
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key3", "value3");
    Map<String, Object> errorParams = new HashMap<>();
    errorParams.put("key4", "value4");
    Map<String, Object> intrinsics = new HashMap<>();
    intrinsics.put("key5", "value5");
    intrinsics.put("key6", 7.77);
    intrinsics.put("key7", 18L);
    TransactionData data = createTransactionData(true, 0, error, false, requestParams, userParams, agentParams, errorParams, intrinsics);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, new StatsEngineImpl());
    Assert.assertEquals(1, actualErrors.size());
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(actualErrors.get(0));
    Assert.assertNotNull(serializedError);
    Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
    Assert.assertEquals(4, params.size());
    Assert.assertNotNull(params.get("stack_trace"));
    Assert.assertNotNull(params.get("intrinsics"));
    Assert.assertNotNull(params.get("agentAttributes"));
    Assert.assertNotNull(params.get("userAttributes"));
    Map<String, Object> actual = (Map<String, Object>) params.get("intrinsics");
    Assert.assertEquals(8, actual.size());
    Assert.assertEquals("value5", actual.get("key5"));
    Assert.assertEquals(7.77, (Double) actual.get("key6"), .001);
    Assert.assertEquals(18L, actual.get("key7"));
    Assert.assertEquals(false, actual.get("error.expected"));
    actual = (Map<String, Object>) params.get("agentAttributes");
    Assert.assertEquals(3, actual.size());
    Assert.assertEquals("value1", actual.get("request.parameters.key1"));
    Assert.assertEquals(2L, actual.get("key2"));
    Assert.assertEquals("/dude", actual.get("request.uri"));
    actual = (Map<String, Object>) params.get("userAttributes");
    Assert.assertEquals(2, actual.size());
    Assert.assertEquals("value3", actual.get("key3"));
    Assert.assertEquals("value4", actual.get("key4"));
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionData(com.newrelic.agent.TransactionData) HashMap(java.util.HashMap) Map(java.util.Map) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 49 with StatsEngineImpl

use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method attributesDisabled.

@SuppressWarnings("unchecked")
@Test
public void attributesDisabled() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    setConfigAttributes(config, false, true);
    EventTestHelper.createServiceManager(config);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key2", 2L);
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key3", "value3");
    Map<String, Object> errorParams = new HashMap<>();
    errorParams.put("key4", "value4");
    Map<String, Object> intrinsics = new HashMap<>();
    TransactionData data = createTransactionData(true, 0, error, false, requestParams, userParams, agentParams, errorParams, intrinsics);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, new StatsEngineImpl());
    Assert.assertEquals(1, actualErrors.size());
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(actualErrors.get(0));
    Assert.assertNotNull(serializedError);
    Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
    Assert.assertEquals(2, params.size());
    Assert.assertNotNull(params.get("stack_trace"));
    Map<String, Object> intrinsicsParam = (Map<String, Object>) params.get("intrinsics");
    Assert.assertEquals(false, intrinsicsParam.get("error.expected"));
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionData(com.newrelic.agent.TransactionData) HashMap(java.util.HashMap) Map(java.util.Map) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 50 with StatsEngineImpl

use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method attributesDisabledWithIntrinsics.

@SuppressWarnings("unchecked")
@Test
public void attributesDisabledWithIntrinsics() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    setConfigAttributes(config, false, true);
    EventTestHelper.createServiceManager(config);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("key1", "value1");
    Map<String, Object> agentParams = new HashMap<>();
    agentParams.put("key2", 2L);
    Map<String, Object> userParams = new HashMap<>();
    userParams.put("key3", "value3");
    Map<String, Object> errorParams = new HashMap<>();
    errorParams.put("key4", "value4");
    Map<String, Object> intrinsics = new HashMap<>();
    intrinsics.put("key5", "value5");
    TransactionData data = createTransactionData(true, 0, error, false, requestParams, userParams, agentParams, errorParams, intrinsics);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, new StatsEngineImpl());
    Assert.assertEquals(1, actualErrors.size());
    JSONArray serializedError = (JSONArray) AgentHelper.serializeJSON(actualErrors.get(0));
    Assert.assertNotNull(serializedError);
    Map<String, Object> params = (Map<String, Object>) serializedError.get(4);
    Assert.assertEquals(2, params.size());
    Assert.assertNotNull(params.get("stack_trace"));
    Assert.assertNotNull(params.get("intrinsics"));
    Map<String, Object> actual = (Map<String, Object>) params.get("intrinsics");
    Assert.assertEquals(6, actual.size());
    Assert.assertEquals("value5", actual.get("key5"));
    Assert.assertEquals(false, actual.get("error.expected"));
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionData(com.newrelic.agent.TransactionData) HashMap(java.util.HashMap) Map(java.util.Map) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)53 Test (org.junit.Test)46 StatsEngine (com.newrelic.agent.stats.StatsEngine)31 HashMap (java.util.HashMap)30 JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)20 MockRPMService (com.newrelic.agent.MockRPMService)18 MockHarvestService (com.newrelic.agent.MockHarvestService)13 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)12 SqlTracer (com.newrelic.agent.tracers.SqlTracer)12 Tracer (com.newrelic.agent.tracers.Tracer)12 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)12 Map (java.util.Map)9 JSONArray (org.json.simple.JSONArray)6 SqlObfuscator (com.newrelic.agent.database.SqlObfuscator)5 TransactionStats (com.newrelic.agent.stats.TransactionStats)5 ArrayList (java.util.ArrayList)5 MBeanServer (javax.management.MBeanServer)5 TransactionData (com.newrelic.agent.TransactionData)4 TransactionService (com.newrelic.agent.TransactionService)4 Attribute (javax.management.Attribute)4