Search in sources :

Example 16 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class RPMServiceTest method doTestTracedErrorsSizeLimit.

private void doTestTracedErrorsSizeLimit() throws Exception {
    List<String> appNames = new ArrayList<>(1);
    appNames.add("MyApplication");
    final AtomicInteger errorSentCount = new AtomicInteger(0);
    RPMService svc = new RPMService(appNames, null, null, new DataSenderListener() {

        @Override
        public void dataSent(String method, String encoding, String uri, byte[] rawDataSent) {
            if (method.equals("error_data")) {
                errorSentCount.incrementAndGet();
                // Check that the raw data sent is less than the collector limit of 1MB (1000000 bytes)
                assertTrue(rawDataSent.length < 1000000);
            }
        }

        @Override
        public void dataReceived(String method, String encoding, String uri, Map<?, ?> rawDataReceived) {
            if (method.equals("error_data")) {
                // The collector should let us know it only recieved 2 error traces (instead of 5)
                assertEquals(2L, rawDataReceived.get("return_value"));
            }
        }
    }, Collections.<AgentConnectionEstablishedListener>emptyList());
    ((MockRPMServiceManager) ServiceFactory.getRPMServiceManager()).setRPMService(svc);
    svc.launch();
    // are big enough to push the final traced error over the limit and thus prevent it from being sent.
    for (int i = 0; i < 5; i++) {
        // Each of these adds 249090 bytes, so we can successfully store 4 (996360 bytes -- 996468 with padding)
        // but the 5th should push it over the limit so we will end up cutting the array in half
        // (which rounds down to 2 elements).
        svc.getErrorService().reportError(new LargeStackThrowableError(null, "", new Exception("Test"), System.currentTimeMillis(), null, null, null, null, null, 97500));
    }
    StatsEngineImpl harvestStatsEngine = new StatsEngineImpl();
    ((ErrorServiceImpl) svc.getErrorService()).harvestTracedErrors("MyApplication", harvestStatsEngine);
    // This will collect the traced errors
    svc.harvest(harvestStatsEngine);
    Thread.sleep(500);
    // one set of errors should get sent because the first will error out
    assertEquals(1, errorSentCount.get());
    svc.shutdown();
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) ArrayList(java.util.ArrayList) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataSenderListener(com.newrelic.agent.transport.DataSenderListener)

Example 17 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class TransactionAppNamingTest method createServiceManager.

@Before
public void createServiceManager() throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    // Needed by TransactionService
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    // Needed by TransactionTraceService
    Map<String, Object> configMap = createConfigMap();
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(configMap), configMap);
    serviceManager.setConfigService(configService);
    // Needed by Transaction
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    EnvironmentService envService = new EnvironmentServiceImpl();
    serviceManager.setEnvironmentService(envService);
    // Null pointers if not set
    serviceManager.setStatsService(Mockito.mock(StatsService.class));
    // Needed by Transaction
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    serviceManager.setAttributesService(new AttributesService());
    // Needed by Transaction
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
    rpmServiceManager.setRPMService(rpmService);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) AttributesService(com.newrelic.agent.attributes.AttributesService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) Before(org.junit.Before)

Example 18 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class HighSecurityAttributesTest method testHighSecurityOffWithOtherDefaultsThroughNoticeErrorAPIMessage.

@Test
public void testHighSecurityOffWithOtherDefaultsThroughNoticeErrorAPIMessage() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        settings.put("high_security", Boolean.FALSE);
        enableBrowser(settings);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, String> atts = new HashMap<>();
        atts.put("abc.thread", "1");
        atts.put("request.many", "1");
        atts.put("message.many", "1");
        atts.put("request.parameters.foo", "1");
        atts.put("request.parameters.bar", "1");
        atts.put("message.parameters.foo", "1");
        atts.put("message.parameters.bar", "1");
        impl.noticeError("hello", atts);
        // user attributes should be off
        Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many");
        verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
        verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getErrorAttributes()), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 19 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class NoticeErrorAttributesTest method testStringifiesAndTruncates.

@Test
public void testStringifiesAndTruncates() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        AttributesService service = new AttributesService();
        manager.setAttributesService(service);
        RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
        RPMService mockRPMService = mock(RPMService.class);
        ErrorService errorService = new ErrorServiceImpl(APP_NAME);
        when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
        when(mockRPMService.getErrorService()).thenReturn(errorService);
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        Map<String, Object> atts = new HashMap<>();
        atts.put("test.foo", new Object() {

            @Override
            public String toString() {
                String base = "a";
                for (int i = 0; i < 10; i++) {
                    base += base;
                }
                return base;
            }
        });
        impl.noticeError("hello", atts);
        Assert.assertEquals(t.getErrorAttributes().keySet(), Sets.newHashSet("test.foo"));
        Assert.assertEquals(255, ((String) t.getErrorAttributes().get("test.foo")).length());
        Assert.assertNotEquals(255, atts.get("test.foo").toString().length());
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) RPMServiceManager(com.newrelic.agent.RPMServiceManager) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ErrorService(com.newrelic.agent.errors.ErrorService) Transaction(com.newrelic.agent.Transaction) RPMService(com.newrelic.agent.RPMService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 20 with ErrorServiceImpl

use of com.newrelic.agent.errors.ErrorServiceImpl in project newrelic-java-agent by newrelic.

the class BrowserTransactionStateTest method createServiceManager.

public static void createServiceManager(Set<String> include, Set<String> exclude) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    // Needed by TransactionService
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    // Needed by TransactionTraceService
    Map<String, Object> map = createConfigMap(include, exclude);
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
    serviceManager.setConfigService(configService);
    // Needed by Transaction
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    // Null pointers if not set
    serviceManager.setStatsService(Mockito.mock(StatsService.class));
    // Needed by Transaction
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    // Needed by Transaction
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName("name");
    rpmService.setErrorService(new ErrorServiceImpl("name"));
    rpmServiceManager.setRPMService(rpmService);
    AttributesService attService = new AttributesService();
    serviceManager.setAttributesService(attService);
    ServiceFactory.setServiceManager(serviceManager);
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ThreadService(com.newrelic.agent.ThreadService) MockConfigService(com.newrelic.agent.MockConfigService) ConfigService(com.newrelic.agent.config.ConfigService) MockServiceManager(com.newrelic.agent.MockServiceManager) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService)

Aggregations

ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)34 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)22 TransactionService (com.newrelic.agent.TransactionService)19 MockRPMService (com.newrelic.agent.MockRPMService)17 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)17 ConfigService (com.newrelic.agent.config.ConfigService)17 MockServiceManager (com.newrelic.agent.MockServiceManager)16 StatsService (com.newrelic.agent.stats.StatsService)16 MockCoreService (com.newrelic.agent.MockCoreService)13 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)13 MockHarvestService (com.newrelic.agent.MockHarvestService)12 ThreadService (com.newrelic.agent.ThreadService)12 HarvestService (com.newrelic.agent.HarvestService)11 AttributesService (com.newrelic.agent.attributes.AttributesService)11 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)9 AgentConfig (com.newrelic.agent.config.AgentConfig)8 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)8 HashMap (java.util.HashMap)8 NormalizationServiceImpl (com.newrelic.agent.normalization.NormalizationServiceImpl)7 Test (org.junit.Test)7