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();
}
}
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();
}
}
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);
}
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());
}
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());
}
Aggregations