Search in sources :

Example 1 with ErrorEvent

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));
        }
    }
}
Also used : ErrorEvent(com.newrelic.agent.model.ErrorEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ErrorEvent

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());
}
Also used : ErrorEvent(com.newrelic.agent.model.ErrorEvent) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService)

Example 3 with ErrorEvent

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"));
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) ErrorEvent(com.newrelic.agent.model.ErrorEvent) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Example 4 with ErrorEvent

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"));
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) ErrorEvent(com.newrelic.agent.model.ErrorEvent) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Example 5 with ErrorEvent

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());
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) ErrorEvent(com.newrelic.agent.model.ErrorEvent) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Aggregations

ErrorEvent (com.newrelic.agent.model.ErrorEvent)12 Test (org.junit.Test)6 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)4 HashMap (java.util.HashMap)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 ThrowableError (com.newrelic.agent.errors.ThrowableError)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)1 MockRPMService (com.newrelic.agent.MockRPMService)1 Transaction (com.newrelic.agent.Transaction)1 TransactionData (com.newrelic.agent.TransactionData)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 DistributedSamplingPriorityQueue (com.newrelic.agent.service.analytics.DistributedSamplingPriorityQueue)1 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)1 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)1 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)1 StatsWork (com.newrelic.agent.stats.StatsWork)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1