Search in sources :

Example 16 with SpanError

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);
}
Also used : TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 17 with SpanError

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);
}
Also used : SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 18 with SpanError

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);
}
Also used : TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 19 with SpanError

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

Aggregations

SpanError (com.newrelic.agent.model.SpanError)19 Test (org.junit.Test)16 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)7 SpanEvent (com.newrelic.agent.model.SpanEvent)2 TransactionData (com.newrelic.agent.TransactionData)1 AgentIdentity (com.newrelic.agent.environment.AgentIdentity)1 Environment (com.newrelic.agent.environment.Environment)1 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)1 ReportableError (com.newrelic.agent.errors.ReportableError)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 Tracer (com.newrelic.agent.tracers.Tracer)1 SpanProxy (com.newrelic.agent.tracing.SpanProxy)1 Before (org.junit.Before)1