Search in sources :

Example 1 with ErrorService

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

the class NoticeErrorAttributesTest method testNoticeErrorAPIFirstCallWins.

@Test
public void testNoticeErrorAPIFirstCallWins() {
    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, String> atts = new HashMap<>();
        atts.put("test.foo", "1");
        impl.noticeError("hello", atts);
        Map<String, String> atts2 = new HashMap<>();
        atts.put("test.bar", "2");
        impl.noticeError("hello", atts2);
        Set<String> expected = Sets.newHashSet("test.foo");
        verifyOutput(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 2 with ErrorService

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

the class HighSecurityAttributesTest method testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIMessage.

@Test
public void testHighSecurityOnWithOtherDefaultsThroughNoticeErrorAPIMessage() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        settings.put("high_security", Boolean.TRUE);
        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 = new HashSet<>();
        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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ErrorService

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

the class ApiTest method after.

@After
public void after() {
    Transaction.clearTransaction();
    ServiceFactory.setServiceManager(apiTestHelper.serviceManager);
    ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
    errorService.getAndClearTracedErrors();
    ServiceFactory.getStatsService().getStatsEngineForHarvest(null).clear();
    ServiceFactory.getTransactionService().addTransactionListener(this);
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) After(org.junit.After)

Example 4 with ErrorService

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

the class ApiTest method testNoticeErrorThrowableParamsOutsideTransaction.

@Test
public void testNoticeErrorThrowableParamsOutsideTransaction() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
    Map<String, String> atts = new HashMap<>();
    atts.put("str", "dude");
    NewRelic.noticeError(new RuntimeException("boom"), atts);
    try {
        // ensure that the errors have different timestamps
        Thread.sleep(5);
    } catch (InterruptedException e) {
    }
    NewRelic.noticeError(new RuntimeException("boom2"), new HashMap<String, String>());
    Collection<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
    Assert.assertEquals("incorrect traced errors count", 2, tracedErrors.size());
    TracedError tracedError = (TracedError) tracedErrors.toArray()[0];
    Assert.assertEquals("error attribute incorrect", "dude", tracedError.getErrorAtts().get("str"));
    Assert.assertEquals("exception class incorrect", "java.lang.RuntimeException", tracedError.getExceptionClass());
    Assert.assertEquals("error message incorrect", "boom", tracedError.getMessage());
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) TracedError(com.newrelic.agent.errors.TracedError) HashMap(java.util.HashMap) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 5 with ErrorService

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

the class ApiTest method testNoticeErrorMsgParamsOutsideTransaction.

@Test
public void testNoticeErrorMsgParamsOutsideTransaction() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    ErrorService errorService = ServiceFactory.getRPMService().getErrorService();
    Map<String, String> atts = new HashMap<>();
    atts.put("str", "dude");
    NewRelic.noticeError("outside1", atts);
    try {
        // ensure that the errors have different timestamps
        Thread.sleep(5);
    } catch (InterruptedException e) {
    }
    NewRelic.noticeError("outside2", new HashMap<String, String>());
    Collection<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
    Assert.assertEquals("incorrect traced errors count", 2, tracedErrors.size());
    TracedError tracedError = (TracedError) tracedErrors.toArray()[0];
    Assert.assertEquals("error attribute incorrect", "dude", tracedError.getErrorAtts().get("str"));
    // getExceptionClass on a HTTPTracedError is getMessage
    Assert.assertEquals("exception class incorrect", "outside1", tracedError.getExceptionClass());
    Assert.assertEquals("error message incorrect", "outside1", tracedError.getMessage());
}
Also used : ErrorService(com.newrelic.agent.errors.ErrorService) TracedError(com.newrelic.agent.errors.TracedError) HashMap(java.util.HashMap) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Aggregations

ErrorService (com.newrelic.agent.errors.ErrorService)15 Test (org.junit.Test)11 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)7 Transaction (com.newrelic.agent.Transaction)6 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)6 HashMap (java.util.HashMap)6 RPMServiceManager (com.newrelic.agent.RPMServiceManager)5 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)5 RPMService (com.newrelic.agent.RPMService)4 TransactionService (com.newrelic.agent.TransactionService)4 TracedError (com.newrelic.agent.errors.TracedError)4 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)4 NewRelicApiImplementation (com.newrelic.api.agent.NewRelicApiImplementation)4 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 After (org.junit.After)2 IRPMService (com.newrelic.agent.IRPMService)1 MockServiceManager (com.newrelic.agent.MockServiceManager)1 HashSet (java.util.HashSet)1