Search in sources :

Example 6 with ErrorEvent

use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.

the class SpanIdOnErrorsTest method matchFirstErrorToOriginatingSpan.

private void matchFirstErrorToOriginatingSpan(String expectedSpanName) {
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    final DistributedSamplingPriorityQueue<ErrorEvent> reservoir = errorService.getReservoir(ServiceFactory.getRPMService().getApplicationName());
    assertTrue(reservoir.size() > 0);
    final ErrorEvent errorEvent = reservoir.asList().get(0);
    assertTrue(errorEvent.getAgentAttributes().containsKey("spanId"));
    assertMethodWhereErrorOriginatedHasThisSpanId(errorEvent.getAgentAttributes().get("spanId"), expectedSpanName);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) ErrorEvent(com.newrelic.agent.model.ErrorEvent)

Example 7 with ErrorEvent

use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.

the class SpanIdOnErrorsTest method noTransactionErrorIfErrorIsHandled.

@Test
public void noTransactionErrorIfErrorIsHandled() {
    runTransaction(new SpanErrorFlow.ThrowHandledException());
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    final DistributedSamplingPriorityQueue<ErrorEvent> reservoir = errorService.getReservoir(ServiceFactory.getRPMService().getApplicationName());
    assertEquals(0, reservoir.size());
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) ErrorEvent(com.newrelic.agent.model.ErrorEvent) Test(org.junit.Test)

Example 8 with ErrorEvent

use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.

the class IntrospectorErrorService method reportError.

@Override
protected void reportError(TracedError error, TransactionData transactionData, TransactionStats transactionStats) {
    if (error == null) {
        return;
    }
    if (error instanceof ThrowableError && getErrorAnalyzer().isIgnoredError(HttpURLConnection.HTTP_OK, ((ThrowableError) error).getThrowable())) {
        return;
    }
    ErrorEvent event = ErrorServiceImpl.createErrorEvent("TestApp", error, transactionData, transactionStats);
    if (transactionData == null) {
        errorsOutsideTransactions.add(new ErrorImpl(error));
        errorEventsOutsideTransactions.add(new ErrorEventImpl(event));
    } else {
        String txName = transactionData.getPriorityTransactionName().getName();
        errors.put(txName, new ErrorImpl(error));
        errorEvents.put(txName, new ErrorEventImpl(event));
    }
}
Also used : ErrorEvent(com.newrelic.agent.model.ErrorEvent) ThrowableError(com.newrelic.agent.errors.ThrowableError)

Example 9 with ErrorEvent

use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.

the class ErrorServiceImpl method harvestEvents.

public void harvestEvents(final String appName) {
    boolean eventsEnabled = isEventsEnabledForApp(appName);
    if (!eventsEnabled) {
        reservoirForApp.remove(appName);
        return;
    }
    if (maxSamplesStored <= 0) {
        clearReservoir(appName);
        return;
    }
    long startTimeInNanos = System.nanoTime();
    final DistributedSamplingPriorityQueue<ErrorEvent> reservoir = reservoirForApp.put(appName, new DistributedSamplingPriorityQueue<ErrorEvent>(appName, "Error Service", maxSamplesStored));
    if (reservoir != null && reservoir.size() > 0) {
        try {
            ServiceFactory.getRPMServiceManager().getOrCreateRPMService(appName).sendErrorEvents(maxSamplesStored, reservoir.getNumberOfTries(), Collections.unmodifiableList(reservoir.asList()));
            final long durationInNanos = System.nanoTime() - startTimeInNanos;
            ServiceFactory.getStatsService().doStatsWork(new StatsWork() {

                @Override
                public void doWork(StatsEngine statsEngine) {
                    recordSupportabilityMetrics(statsEngine, durationInNanos, reservoir);
                }

                @Override
                public String getAppName() {
                    return appName;
                }
            }, reservoir.getServiceName());
            if (reservoir.size() < reservoir.getNumberOfTries()) {
                int dropped = reservoir.getNumberOfTries() - reservoir.size();
                Agent.LOG.log(Level.FINE, "Dropped {0} error events out of {1}.", dropped, reservoir.getNumberOfTries());
            }
        } catch (HttpError e) {
            if (!e.discardHarvestData()) {
                Agent.LOG.log(Level.FINE, "Unable to send error events. Unsent events will be included in the next harvest.", e);
                // Save unsent data by merging it with current data using reservoir algorithm
                DistributedSamplingPriorityQueue<ErrorEvent> currentReservoir = reservoirForApp.get(appName);
                currentReservoir.retryAll(reservoir);
            } else {
                // discard harvest data
                reservoir.clear();
                Agent.LOG.log(Level.FINE, "Unable to send error events. Unsent events will be dropped.", e);
            }
        } catch (Exception e) {
            // discard harvest data
            reservoir.clear();
            Agent.LOG.log(Level.FINE, "Unable to send error events. Unsent events will be dropped.", e);
        }
    }
}
Also used : StatsWork(com.newrelic.agent.stats.StatsWork) ErrorEvent(com.newrelic.agent.model.ErrorEvent) HttpError(com.newrelic.agent.transport.HttpError) DistributedSamplingPriorityQueue(com.newrelic.agent.service.analytics.DistributedSamplingPriorityQueue) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 10 with ErrorEvent

use of com.newrelic.agent.model.ErrorEvent in project newrelic-java-agent by newrelic.

the class DataCollectionConfigCrossAgentTest method createAndVerifyErrorEvent.

private void createAndVerifyErrorEvent(Long expectedCount, Long expectedEndpointCount) {
    ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
    rpmService.setErrorService(errorService);
    long eventsToCreate = 1;
    if (expectedCount > 1) {
        eventsToCreate = expectedCount;
    }
    for (long i = 0; i < eventsToCreate; i++) {
        ThrowableError error = ThrowableError.builder(errorService.getErrorCollectorConfig(), APP_NAME, "metric", new Throwable(), System.currentTimeMillis()).build();
        errorService.reportError(error);
    }
    // Verify that the correct number of events were stored in the reservoir
    DistributedSamplingPriorityQueue<ErrorEvent> eventQueue = errorService.getReservoir(APP_NAME);
    assertNotNull(eventQueue);
    assertEquals(expectedCount.intValue(), eventQueue.size());
    // Verify that we sent (or didn't send) the appropriate events
    errorService.harvestEvents(APP_NAME);
    int errorEventsSeen = rpmService.getErrorEventsSeen();
    assertEquals(expectedEndpointCount.intValue(), errorEventsSeen);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) ErrorEvent(com.newrelic.agent.model.ErrorEvent) ThrowableError(com.newrelic.agent.errors.ThrowableError)

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