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