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