use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.
the class ErrorServiceImpl method reportError.
// Introspector subclasses this class
@VisibleForTesting
protected void reportError(TracedError error, TransactionData transactionData, TransactionStats transactionStats) {
if (error == null) {
return;
}
if (error instanceof ThrowableError && getErrorAnalyzer().isIgnoredThrowable(((ThrowableError) error).getThrowable())) {
if (Agent.LOG.isLoggable(Level.FINER)) {
Throwable throwable = ((ThrowableError) error).getThrowable();
String errorString = throwable == null ? "" : throwable.getClass().getName();
String msg = MessageFormat.format("Ignoring error {0} for {1}", errorString, appName);
Agent.LOG.finer(msg);
}
return;
}
if (error.incrementsErrorMetric()) {
errorCountThisHarvest.incrementAndGet();
} else if (!(error instanceof DeadlockTraceError)) {
expectedErrorCountThisHarvest.incrementAndGet();
}
if (!errorCollectorConfig.isEnabled() || !isEventsEnabledForApp(appName) || maxSamplesStored <= 0) {
return;
}
// Siphon off errors to send up as error events
DistributedSamplingPriorityQueue<ErrorEvent> eventList = getReservoir(appName);
ErrorEvent errorEvent = createErrorEvent(appName, error, transactionData, transactionStats);
eventList.add(errorEvent);
if (errorCount.get() >= ERROR_LIMIT_PER_REPORTING_PERIOD) {
Agent.LOG.finer(MessageFormat.format("Error limit exceeded for {0}: {1}", appName, error));
return;
}
int index = (int) totalErrorCount.getAndIncrement() % ERROR_LIMIT_PER_REPORTING_PERIOD;
if (tracedErrors.compareAndSet(index, null, error)) {
errorCount.getAndIncrement();
if (Agent.LOG.isLoggable(Level.FINER)) {
Agent.LOG.finer(MessageFormat.format("Recording error for {0} : {1}", appName, error));
}
}
}
use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.
the class ErrorServiceTest method checkForEvent.
private void checkForEvent() {
StatsEngine statsEngineForHarvest = ServiceFactory.getStatsService().getStatsEngineForHarvest(EventTestHelper.APP_NAME);
Assert.assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_ERROR_SERVICE_TRANSACTION_ERROR_SENT)).hasData());
Assert.assertTrue(statsEngineForHarvest.getStats(MetricName.create(MetricNames.SUPPORTABILITY_ERROR_SERVICE_TRANSACTION_ERROR_SEEN)).hasData());
Assert.assertEquals(1, ((MockRPMService) ServiceFactory.getRPMService()).getEvents().size());
ErrorEvent errorEvent = (ErrorEvent) Iterables.get(((MockRPMService) ServiceFactory.getRPMService()).getEvents(), 0);
Assert.assertEquals(errorEvent.getUserAttributesCopy().get("test_attribute"), "value");
Assert.assertEquals("TransactionError", errorEvent.getType());
}
use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.
the class ExpectedErrorFactoryTest method testExpectedErrorEvent.
@Test
public void testExpectedErrorEvent() throws Exception {
Map<String, Object> configuration = new HashMap<>();
configuration.put("error_collector:expected_status_codes", 403);
configuration = buildConfigMap(configuration);
ErrorCollectorConfig errorCollectorConfig = setupServices(configuration);
TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
ErrorEvent event = ErrorEventFactory.create(appName, error, DistributedTraceServiceImpl.nextTruncatedFloat());
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
JSONObject jsonObject = (JSONObject) jsonArray.get(0);
assertEquals(true, jsonObject.get("error.expected"));
}
use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.
the class ExpectedErrorFactoryTest method testNonExpectedErrorEvent.
@Test
public void testNonExpectedErrorEvent() throws Exception {
Map<String, Object> configuration = new HashMap<>();
configuration.put("error_collector:expected_status_codes", 403);
configuration = buildConfigMap(configuration);
ErrorCollectorConfig errorCollectorConfig = setupServices(configuration);
TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(420, null).requestUri("/dude").build();
ErrorEvent event = ErrorEventFactory.create(appName, error, DistributedTraceServiceImpl.nextTruncatedFloat());
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
JSONObject jsonObject = (JSONObject) jsonArray.get(0);
Assert.assertFalse((Boolean) jsonObject.get("error.expected"));
}
use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.
the class ExpectedErrorFactoryTest method testNonTruncatedErrorEvent.
@Test
public void testNonTruncatedErrorEvent() throws Exception {
Map<String, Object> configuration = new HashMap<>();
configuration = buildConfigMap(configuration);
ErrorCollectorConfig errorCollectorConfig = setupServices(configuration);
StringBuilder errorMessageBuilder = new StringBuilder();
for (int i = 0; i < 250; i++) {
errorMessageBuilder.append("1");
}
String errorMessage = errorMessageBuilder.toString();
TracedError error = HttpTracedError.builder(errorCollectorConfig, appName, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, errorMessage).requestUri("/dude").build();
ErrorEvent event = ErrorEventFactory.create(appName, error, DistributedTraceServiceImpl.nextTruncatedFloat());
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
JSONObject jsonObject = (JSONObject) jsonArray.get(0);
assertEquals(errorMessage, error.getMessage());
assertEquals(errorMessage, error.getExceptionClass());
assertEquals(errorMessage, event.getErrorClass());
assertEquals(errorMessage, jsonObject.get("error.class"));
assertEquals(errorMessage, jsonObject.get("error.message"));
assertEquals(250, jsonObject.get("error.message").toString().length());
assertEquals(250, event.getErrorClass().length());
assertEquals(250, event.getErrorMessage().length());
}
Aggregations