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