Search in sources :

Example 6 with SpanError

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

Example 7 with SpanError

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

Example 8 with SpanError

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

Example 9 with SpanError

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

Example 10 with SpanError

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