use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanErrorBuilderTest method transactionThrowableUsedIfTracerGuidMatches.
@Test
public void transactionThrowableUsedIfTracerGuidMatches() {
final String spanGuid = "SPAN_GUID";
when(mockAnalyzer.isReportable(anyInt(), ArgumentMatchers.<Throwable>any())).thenReturn(true);
when(mockAnalyzer.isReportable(anyInt())).thenReturn(false);
when(mockAnalyzer.isIgnoredError(anyInt(), ArgumentMatchers.<Throwable>any())).thenReturn(false);
when(mockTracer.getException()).thenReturn(null);
when(mockTracer.wasExceptionSetByAPI()).thenReturn(false);
when(mockTracer.getGuid()).thenReturn(spanGuid);
when(mockReplacer.getMessage(ArgumentMatchers.<Throwable>any())).thenReturn("replaced message");
SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, false, 400, "fine", new TransactionThrowable(new IllegalAccessException("something"), false, spanGuid));
assertSpanError(target, null, IllegalAccessException.class, "replaced message", false);
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanErrorBuilderTest method shouldAddErrorClassAndMessageToSpanError.
@Test
public void shouldAddErrorClassAndMessageToSpanError() {
when(mockAnalyzer.isReportable(anyInt(), ArgumentMatchers.<Throwable>any())).thenReturn(true);
when(mockAnalyzer.isReportable(anyInt())).thenReturn(false);
when(mockTracer.getException()).thenReturn(new RuntimeException());
when(mockTracer.wasExceptionSetByAPI()).thenReturn(false);
when(mockReplacer.getMessage(ArgumentMatchers.<Throwable>any())).thenReturn("replaced message");
SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, false, 400, "fine", null);
assertSpanError(target, null, RuntimeException.class, "replaced message", false);
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class SpanErrorBuilderTest method shouldIgnoreExpectedErrorOnThrowable.
@Test
public void shouldIgnoreExpectedErrorOnThrowable() {
final String spanGuid = "SPAN_GUID";
TransactionThrowable fakeThrowable = new TransactionThrowable(new IllegalArgumentException("what did I do?"), true, spanGuid);
Throwable exceptionOfThrowable = fakeThrowable.throwable;
when(mockAnalyzer.isReportable(400, fakeThrowable)).thenReturn(true);
when(mockAnalyzer.isReportable(anyInt())).thenReturn(true);
when(mockAnalyzer.isIgnoredError(400, exceptionOfThrowable)).thenReturn(true);
when(mockAnalyzer.isExpectedError(400, fakeThrowable)).thenReturn(true);
when(mockTracer.getException()).thenReturn(exceptionOfThrowable);
when(mockTracer.wasExceptionSetByAPI()).thenReturn(true);
SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, true, 400, "fine", fakeThrowable);
assertEmptySpanError(target);
}
use of com.newrelic.agent.model.SpanError in project newrelic-java-agent by newrelic.
the class TracerToSpanEvent method maybeSetError.
private SpanEventFactory maybeSetError(Tracer tracer, TransactionData transactionData, boolean isRoot, SpanEventFactory builder) {
SpanErrorBuilder spanErrorBuilder = errorBuilderForApp.get(transactionData.getApplicationName());
spanErrorBuilder = spanErrorBuilder == null ? defaultSpanErrorBuilder : spanErrorBuilder;
if (spanErrorBuilder.areErrorsEnabled()) {
final SpanError spanError = spanErrorBuilder.buildSpanError(tracer, isRoot, transactionData.getResponseStatus(), transactionData.getStatusMessage(), transactionData.getThrowable());
return builder.setSpanError(spanError);
}
return builder;
}
Aggregations