Search in sources :

Example 1 with SpanError

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

the class TracerToSpanEventTest method setup.

@Before
public void setup() {
    transactionAgentAttributes = new HashMap<>();
    transactionUserAttributes = new HashMap<>();
    tracerAgentAttributes = new HashMap<>();
    tracerUserAttributes = new HashMap<>();
    expectedAgentAttributes = new HashMap<>();
    expectedUserAttributes = new HashMap<>();
    expectedAgentAttributes.put("error.class", "0");
    expectedAgentAttributes.put("port", 9191);
    expectedIntrinsicAttributes = new HashMap<>();
    expectedIntrinsicAttributes.put("traceId", traceId);
    expectedIntrinsicAttributes.put("duration", (float) duration / TimeConversion.NANOSECONDS_PER_SECOND);
    expectedIntrinsicAttributes.put("type", "Span");
    expectedIntrinsicAttributes.put("category", "generic");
    expectedIntrinsicAttributes.put("sampled", sampled);
    expectedIntrinsicAttributes.put("nr.entryPoint", true);
    expectedIntrinsicAttributes.put("timestamp", timestamp);
    expectedIntrinsicAttributes.put("priority", priority);
    expectedIntrinsicAttributes.put("transaction.name", txnName.getName());
    tracer = mock(Tracer.class);
    txnData = mock(TransactionData.class);
    spanErrorBuilder = mock(SpanErrorBuilder.class);
    spanError = mock(SpanError.class);
    spanProxy = mock(SpanProxy.class);
    throwable = mock(TransactionThrowable.class);
    environmentService = mock(EnvironmentService.class);
    environment = mock(Environment.class);
    transactionDataToDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
    txnStats = mock(TransactionStats.class, RETURNS_DEEP_STUBS);
    errorBuilderMap = new HashMap<>();
    errorBuilderMap.put(appName, spanErrorBuilder);
    when(tracer.getDuration()).thenReturn(duration);
    when(tracer.getStartTimeInMillis()).thenReturn(timestamp);
    when(tracer.getAgentAttributes()).thenReturn(tracerAgentAttributes);
    when(tracer.getCustomAttributes()).thenReturn(tracerUserAttributes);
    when(spanErrorBuilder.buildSpanError(tracer, isRoot, responseStatus, statusMessage, throwable)).thenReturn(spanError);
    when(spanErrorBuilder.areErrorsEnabled()).thenReturn(true);
    when(txnData.getApplicationName()).thenReturn(appName);
    when(txnData.getResponseStatus()).thenReturn(responseStatus);
    when(txnData.getStatusMessage()).thenReturn(statusMessage);
    when(txnData.getThrowable()).thenReturn(throwable);
    when(txnData.getPriority()).thenReturn(priority);
    when(txnData.sampled()).thenReturn(sampled);
    when(txnData.getSpanProxy()).thenReturn(spanProxy);
    when(txnData.getPriorityTransactionName()).thenReturn(txnName);
    when(txnData.getUserAttributes()).thenReturn(transactionUserAttributes);
    when(spanProxy.getOrCreateTraceId()).thenReturn(traceId);
    when(environmentService.getEnvironment()).thenReturn(environment);
    when(environment.getAgentIdentity()).thenReturn(new AgentIdentity("dispatcher", "1.2.3", 9191, "myInstance"));
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) SpanProxy(com.newrelic.agent.tracing.SpanProxy) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) TransactionData(com.newrelic.agent.TransactionData) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Before(org.junit.Before)

Example 2 with SpanError

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

the class SpanErrorBuilderTest method shouldNotDoAnythingIfEitherAreIgnored.

@Test
public void shouldNotDoAnythingIfEitherAreIgnored() {
    when(mockAnalyzer.isReportable(anyInt(), ArgumentMatchers.<Throwable>any())).thenReturn(true);
    when(mockAnalyzer.isReportable(anyInt())).thenReturn(true);
    when(mockAnalyzer.isIgnoredError(anyInt(), ArgumentMatchers.<Throwable>any())).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);
    assertEmptySpanError(target);
}
Also used : SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 3 with SpanError

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

the class SpanErrorBuilderTest method transactionThrowableNotUsedIfTracerGuidDoesNotMatch.

@Test
public void transactionThrowableNotUsedIfTracerGuidDoesNotMatch() {
    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("some guid");
    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, "some other guid"));
    assertEmptySpanError(target);
}
Also used : TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Test(org.junit.Test)

Example 4 with SpanError

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

the class SpanErrorBuilderTest method shouldSetExpectedErrorTrueForSpanErrorOnNonRootSpan.

@Test
public void shouldSetExpectedErrorTrueForSpanErrorOnNonRootSpan() {
    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(0, fakeThrowable)).thenReturn(true);
    SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, false, 400, "This message will not be set", fakeThrowable);
    assertSpanError(target, null, 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 5 with SpanError

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

the class SpanErrorBuilderTest method shouldSetExpectedErrorTrueForExpectedStatusCodeButNoThrownException.

@Test
public void shouldSetExpectedErrorTrueForExpectedStatusCodeButNoThrownException() {
    when(mockAnalyzer.isReportable(400)).thenReturn(true);
    when(mockAnalyzer.isReportable(400, (Throwable) null)).thenReturn(true);
    when(mockAnalyzer.isExpectedError(400, null)).thenReturn(true);
    when(mockTracer.getException()).thenReturn(null);
    SpanError target = new SpanErrorBuilder(mockAnalyzer, mockReplacer).buildSpanError(mockTracer, true, 400, "fine", null);
    assertSpanError(target, 400, null, "fine", true);
}
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