Search in sources :

Example 11 with SpanError

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

the class SpanErrorBuilderTest method shouldBuildEmptySpanErrorWithoutReportableError.

@Test
public void shouldBuildEmptySpanErrorWithoutReportableError() {
    when(mockAnalyzer.isReportable(eq(400), ArgumentMatchers.<Throwable>any())).thenReturn(false);
    when(mockTracer.getException()).thenReturn(null);
    SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, true, 200, "fine", null);
    assertEmptySpanError(target);
}
Also used : SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 12 with SpanError

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

the class SpanErrorBuilderTest method shouldBuildEmptySpanErrorWithReportableStatusOnNonRoot.

@Test
public void shouldBuildEmptySpanErrorWithReportableStatusOnNonRoot() {
    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, false, 400, "fine", null);
    assertEmptySpanError(target);
}
Also used : SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 13 with SpanError

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

the class SpanErrorBuilderTest method shouldSetExpectedErrorTrueForSpanErrorOnRootSpan.

@Test
public void shouldSetExpectedErrorTrueForSpanErrorOnRootSpan() {
    final String spanGuid = "SPAN_GUID";
    TransactionThrowable fakeThrowable = new TransactionThrowable(new IllegalArgumentException("what did I do?"), true, spanGuid);
    when(mockTracer.getGuid()).thenReturn(spanGuid);
    when(mockTracer.wasExceptionSetByAPI()).thenReturn(true);
    when(mockTracer.getException()).thenReturn(fakeThrowable.throwable);
    when(mockAnalyzer.isExpectedError(400, fakeThrowable)).thenReturn(true);
    when(mockAnalyzer.isReportable(400)).thenReturn(true);
    SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, true, 400, "This web response message will be overridden", fakeThrowable);
    assertSpanError(target, 400, IllegalArgumentException.class, "what did I do?", true);
}
Also used : TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 14 with SpanError

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

the class SpanErrorBuilderTest method shouldBypassIgnoreReportableAndReplacementRulesForNoticedErrors.

@Test
public void shouldBypassIgnoreReportableAndReplacementRulesForNoticedErrors() {
    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 RuntimeException("~~ unstripped due to api ~~"));
    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, RuntimeException.class, "~~ unstripped due to api ~~", false);
}
Also used : SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 15 with SpanError

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

the class SpanErrorBuilderTest method shouldAddStatusAndExceptionToRootSpans.

@Test
public void shouldAddStatusAndExceptionToRootSpans() {
    when(mockAnalyzer.isReportable(anyInt(), ArgumentMatchers.<Throwable>any())).thenReturn(true);
    when(mockAnalyzer.isReportable(anyInt())).thenReturn(true);
    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, true, 400, "fine", null);
    assertSpanError(target, 400, RuntimeException.class, "replaced message", false);
}
Also used : SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

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