Search in sources :

Example 1 with TransactionThrowable

use of com.newrelic.agent.transaction.TransactionThrowable in project newrelic-java-agent by newrelic.

the class TransactionDataTest method getThrowable.

@Test
public void getThrowable() {
    Throwable exception = new Exception();
    TransactionThrowable transactionThrowable = new TransactionThrowable(exception, false, null);
    Mockito.when(tx.getThrowable()).thenReturn(transactionThrowable);
    TransactionData txd = getTxData(tx);
    Assert.assertSame(exception, txd.getThrowable().throwable);
}
Also used : TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Test(org.junit.Test)

Example 2 with TransactionThrowable

use of com.newrelic.agent.transaction.TransactionThrowable in project newrelic-java-agent by newrelic.

the class TransactionDataTestBuilder method build.

public TransactionData build() {
    when(tx.getRootTracer()).thenReturn(tracer);
    if (synJobId == null || synMonitorId == null || synResourceId == null) {
        when(tx.isSynthetic()).thenReturn(false);
    } else {
        when(tx.isSynthetic()).thenReturn(true);
    }
    when(tx.getGuid()).thenReturn("guid");
    Dispatcher mockDispatcher = mock(Dispatcher.class);
    when(mockDispatcher.getUri()).thenReturn(requestUri);
    when(mockDispatcher.isWebTransaction()).thenReturn(dispatcher == null ? true : dispatcher.isWebTransaction());
    when(tx.getDispatcher()).thenReturn(mockDispatcher);
    if (throwable != null) {
        when(tx.getThrowable()).thenReturn(new TransactionThrowable(throwable, expectedError, null));
    }
    PriorityTransactionName priorityTransactionName = mock(PriorityTransactionName.class);
    when(priorityTransactionName.getName()).thenReturn(frontendMetricName);
    when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
    Map<String, Map<String, String>> prefixed = new HashMap<>();
    prefixed.put("request.parameters.", requestParams);
    when(tx.getPrefixedAgentAttributes()).thenReturn(prefixed);
    when(tx.getUserAttributes()).thenReturn(userParams);
    when(tx.getAgentAttributes()).thenReturn(agentParams);
    when(tx.getErrorAttributes()).thenReturn(errorParams);
    when(tx.getIntrinsicAttributes()).thenReturn(intrinsics);
    when(tx.isIgnore()).thenReturn(false);
    when(tx.getStatus()).thenReturn(responseStatus);
    when(tx.getStatusMessage()).thenReturn(statusMessage);
    when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
    when(tx.getSpanProxy()).thenReturn(new SpanProxy());
    ErrorServiceImpl errorService = mock(ErrorServiceImpl.class);
    IRPMService rpmService = mock(IRPMService.class);
    when(rpmService.getApplicationName()).thenReturn(appName);
    when(rpmService.getErrorService()).thenReturn(errorService);
    when(tx.getRPMService()).thenReturn(rpmService);
    when(tx.getAgentConfig()).thenReturn(agentConfig);
    when(tx.getWallClockStartTimeMs()).thenReturn(startTime);
    if (slowQueryListener != null) {
        when(tx.getSlowQueryListener(anyBoolean())).thenReturn(slowQueryListener);
    }
    when(tx.getTracers()).thenReturn(tracers);
    CrossProcessTransactionState crossProcessTransactionState = mock(CrossProcessTransactionState.class);
    when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
    when(crossProcessTransactionState.getTripId()).thenReturn("tripId");
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getSyntheticsJobId()).thenReturn(synJobId);
    when(ihs.getSyntheticsMonitorId()).thenReturn(synMonitorId);
    when(ihs.getSyntheticsResourceId()).thenReturn(synResourceId);
    when(ihs.getSyntheticsVersion()).thenReturn(HeadersUtil.SYNTHETICS_MIN_VERSION);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    TransactionTimer timer = new TransactionTimer(tracer.getStartTime());
    timer.markTransactionActivityAsDone(tracer.getEndTime(), tracer.getDuration());
    timer.markTransactionAsDone();
    when(tx.getTransactionTimer()).thenReturn(timer);
    // when(tx.getApplicationName()).thenReturn(appName);
    Set<TransactionActivity> activities = new HashSet<>();
    for (Map.Entry<Long, Collection<Duration>> entry : threadIdToDuration.asMap().entrySet()) {
        for (Duration duration : entry.getValue()) {
            TransactionActivity activity = mock(TransactionActivity.class);
            when(activity.getThreadId()).thenReturn(entry.getKey());
            Tracer rootTracer = mock(Tracer.class);
            when(rootTracer.getStartTime()).thenReturn(duration.startTime);
            when(rootTracer.getEndTime()).thenReturn(duration.endTime);
            when(activity.getRootTracer()).thenReturn(rootTracer);
            activities.add(activity);
        }
    }
    when(tx.getFinishedChildren()).thenReturn(activities);
    if (includeDistributedTracePayload) {
        SpanProxy spanProxy = mock(SpanProxy.class);
        DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload("abc", "def", "def", new Random().nextFloat());
        when(spanProxy.getInboundDistributedTracePayload()).thenReturn(payload);
        when(tx.getSpanProxy()).thenReturn(spanProxy);
    }
    return new TransactionData(tx, 0);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) SpanProxy(com.newrelic.agent.tracing.SpanProxy) Tracer(com.newrelic.agent.tracers.Tracer) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Random(java.util.Random) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Collection(java.util.Collection) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with TransactionThrowable

use of com.newrelic.agent.transaction.TransactionThrowable in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeThrowableWithTooManyParams.

@Test
public void testNoticeThrowableWithTooManyParams() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    try {
        tx.getTransactionActivity().tracerStarted(tracer);
        Map<String, String> atts = Maps.newHashMapWithExpectedSize(100);
        for (int i = 0; i < 70; i++) {
            atts.put("key" + i, "value");
        }
        Throwable t = new Throwable("test");
        NewRelic.noticeError(t, atts);
        Class<? extends Transaction> c = tx.getClass();
        Method m = c.getDeclaredMethod("getThrowable");
        TransactionThrowable transactionThrowable = (TransactionThrowable) m.invoke(tx);
        Assert.assertEquals("test", transactionThrowable.throwable.getMessage());
        Assert.assertEquals(64, tx.getErrorAttributes().size());
    } finally {
        tx.getTransactionActivity().tracerFinished(tracer, 0);
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Method(java.lang.reflect.Method) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 4 with TransactionThrowable

use of com.newrelic.agent.transaction.TransactionThrowable in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorNullThrowableParamsInsideTransaction.

@Test
public void testNoticeErrorNullThrowableParamsInsideTransaction() {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    NewRelic.noticeError((String) null, new HashMap<String, String>());
    try {
        Class<? extends Transaction> c = tx.getClass();
        Method m = c.getDeclaredMethod("getThrowable");
        TransactionThrowable transactionThrowable = (TransactionThrowable) m.invoke(tx);
        Assert.assertNull(transactionThrowable.throwable.getMessage());
    } catch (SecurityException | InvocationTargetException | IllegalArgumentException | NoSuchMethodException | IllegalAccessException e) {
    }
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Transaction(com.newrelic.agent.Transaction) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 5 with TransactionThrowable

use of com.newrelic.agent.transaction.TransactionThrowable in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorWithParamsObjects.

@Test
public void testNoticeErrorWithParamsObjects() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    try {
        tx.getTransactionActivity().tracerStarted(tracer);
        Map<String, Object> atts = new HashMap<>();
        atts.put("one", 5);
        atts.put("three", 6);
        NewRelic.noticeError("boom", atts);
        Class<? extends Transaction> c = tx.getClass();
        Method m = c.getDeclaredMethod("getThrowable");
        TransactionThrowable transactionThrowable = (TransactionThrowable) m.invoke(tx);
        Assert.assertEquals("boom", transactionThrowable.throwable.getMessage());
        Assert.assertEquals(2, tx.getErrorAttributes().size());
        Assert.assertEquals(5, tx.getErrorAttributes().get("one"));
        Assert.assertEquals(6, tx.getErrorAttributes().get("three"));
    } finally {
        tx.getTransactionActivity().tracerFinished(tracer, 0);
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Method(java.lang.reflect.Method) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Aggregations

TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)33 Test (org.junit.Test)30 Transaction (com.newrelic.agent.Transaction)16 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)16 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)16 Method (java.lang.reflect.Method)16 HashMap (java.util.HashMap)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 SpanError (com.newrelic.agent.model.SpanError)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 ServletRequest (javax.servlet.ServletRequest)5 ServletResponse (javax.servlet.ServletResponse)5 HttpServlet (javax.servlet.http.HttpServlet)5 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 ErrorCollectorConfig (com.newrelic.agent.config.ErrorCollectorConfig)2 ErrorService (com.newrelic.agent.errors.ErrorService)2 Tracer (com.newrelic.agent.tracers.Tracer)2 TransactionTimer (com.newrelic.agent.transaction.TransactionTimer)2 ExpectedErrorConfig (com.newrelic.agent.config.ExpectedErrorConfig)1