Search in sources :

Example 56 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeThrowableWithParamsValueTooLarge.

@Test
public void testNoticeThrowableWithParamsValueTooLarge() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    try {
        tx.getTransactionActivity().tracerStarted(tracer);
        Map<String, String> atts = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 258; i++) {
            sb.append("A");
        }
        atts.put("one", sb.toString());
        atts.put("three", "four");
        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(2, tx.getErrorAttributes().size());
        Assert.assertEquals(sb.substring(0, 255), tx.getErrorAttributes().get("one"));
        Assert.assertEquals("four", 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) 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 57 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testGetBrowserTimingHeader.

@Test
public void testGetBrowserTimingHeader() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    String browserTimingHeader = NewRelic.getBrowserTimingHeader();
    Assert.assertEquals("Incorrect header", ApiTestHelper.HEADER, browserTimingHeader);
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 58 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorWithParamsValueTooLarge.

@Test
public void testNoticeErrorWithParamsValueTooLarge() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    try {
        tx.getTransactionActivity().tracerStarted(tracer);
        Map<String, String> atts = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 258; i++) {
            sb.append("A");
        }
        atts.put("one", sb.toString());
        atts.put("three", "four");
        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(sb.substring(0, 255), tx.getErrorAttributes().get("one"));
        Assert.assertEquals("four", 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)

Example 59 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class ApiTest method testNoticeErrorThrowableObjectParamsInTransaction.

@Test
public void testNoticeErrorThrowableObjectParamsInTransaction() throws Exception {
    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(new RuntimeException("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)

Example 60 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class TransactionTest method recordCpuAndGCTimeNotEnabled.

@Test
public void recordCpuAndGCTimeNotEnabled() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    configMap.put(AgentConfigImpl.THREAD_CPU_TIME_ENABLED, Boolean.FALSE);
    createServiceManager(configMap);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    finishTransaction(tx, rootTracer);
    Long cpuTime = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    assertNull(cpuTime);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Aggregations

BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)85 Test (org.junit.Test)67 Transaction (com.newrelic.agent.Transaction)64 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)33 HashMap (java.util.HashMap)22 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)18 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)16 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)16 Method (java.lang.reflect.Method)16 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)15 SegmentTest (com.newrelic.agent.transaction.SegmentTest)15 TransactionNamePriority (com.newrelic.agent.bridge.TransactionNamePriority)14 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)14 TransactionService (com.newrelic.agent.TransactionService)8 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)8 NewRelicApiImplementation (com.newrelic.api.agent.NewRelicApiImplementation)8 ArrayList (java.util.ArrayList)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Tracer (com.newrelic.agent.tracers.Tracer)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7