use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanEventFactoryTest method shouldNotSetSpanErrorWhenFiltered.
@Test
public void shouldNotSetSpanErrorWhenFiltered() {
SpanError spanError = new SpanError();
spanError.setErrorClass(RuntimeException.class);
spanError.setErrorStatus(500);
spanError.setErrorMessage("not again");
SpanEventFactory target = new SpanEventFactory("blerb", new PassNothingAttributeFilter(), DEFAULT_SYSTEM_TIMESTAMP_SUPPLIER);
SpanEvent spanEvent = target.setSpanError(spanError).build();
assertEquals(0, spanEvent.getAgentAttributes().size());
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanEventFactoryTest method shouldSetSpanErrorWithOnlyErrorClassAndMessage.
@Test
public void shouldSetSpanErrorWithOnlyErrorClassAndMessage() {
SpanError spanError = new SpanError();
spanError.setErrorClass(RuntimeException.class);
spanError.setErrorStatus(500);
spanError.setErrorMessage("not again");
SpanEvent target = spanEventFactory.setSpanError(spanError).build();
assertEquals(RuntimeException.class.getName(), target.getAgentAttributes().get("error.class"));
assertEquals(null, target.getAgentAttributes().get("error.status"));
assertEquals("not again", target.getAgentAttributes().get("error.message"));
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanErrorBuilder method buildSpanError.
public SpanError buildSpanError(ErrorTracer tracer, boolean isRoot, int responseStatus, String statusMessage, TransactionThrowable transactionThrowable) {
Throwable throwable = extractThrowable(tracer, transactionThrowable);
int statusCode = isRoot ? responseStatus : ErrorAnalyzer.NO_STATUS;
if (analyzer.isIgnoredError(statusCode, throwable)) {
return new SpanError();
}
if (!isErrorSetByAPI(tracer)) {
if (!analyzer.isReportable(statusCode, throwable)) {
return new SpanError();
}
}
SpanError result = new SpanError();
result.setExpectedError(identifyExpectedError(statusCode, transactionThrowable));
if (analyzer.isReportable(statusCode)) {
result.setErrorStatus(statusCode);
result.setErrorMessage(statusMessage);
}
if (throwable != null) {
result.setErrorMessage(identifyErrorMessage(tracer, throwable));
result.setErrorClass(identifyErrorClass(throwable));
}
return result;
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanErrorBuilderTest method shouldOmitClassForNoticeErrorStringAPI.
@Test
public void shouldOmitClassForNoticeErrorStringAPI() {
when(mockAnalyzer.isReportable(anyInt(), ArgumentMatchers.<Throwable>any())).thenThrow(new AssertionError("should not have been called"));
when(mockAnalyzer.isReportable(anyInt())).thenReturn(false);
when(mockTracer.getException()).thenReturn(new ReportableError("will not be replaced"));
when(mockTracer.wasExceptionSetByAPI()).thenReturn(true);
when(mockReplacer.getMessage(ArgumentMatchers.<Throwable>any())).thenThrow(new AssertionError("should not have been called"));
SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, false, 400, "fine", null);
assertSpanError(target, null, null, "will not be replaced", false);
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanErrorBuilderTest method shouldBuildSpanErrorWithReportableStatusOnRoot.
@Test
public void shouldBuildSpanErrorWithReportableStatusOnRoot() {
when(mockAnalyzer.isReportable(eq(400), ArgumentMatchers.<Throwable>any())).thenReturn(true);
when(mockAnalyzer.isReportable(400)).thenReturn(true);
when(mockAnalyzer.isIgnoredError(anyInt(), ArgumentMatchers.<Throwable>any())).thenReturn(false);
when(mockTracer.getException()).thenReturn(null);
SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, true, 400, "fine", null);
assertSpanError(target, 400, null, "fine", false);
}
Aggregations