Search in sources :

Example 46 with BasicRequestRootTracer

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

the class ApiTest method testNoticeErrorWithParams.

@Test
public void testNoticeErrorWithParams() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    try {
        tx.getTransactionActivity().tracerStarted(tracer);
        Map<String, String> atts = new HashMap<>();
        atts.put("one", "two");
        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("two", 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 47 with BasicRequestRootTracer

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

the class ApiTest method testGetBrowserTimingHeaderWhenRUMEnabledNotSpecified.

@Test
public void testGetBrowserTimingHeaderWhenRUMEnabledNotSpecified() throws Exception {
    Map<String, Object> connectionResponse = new HashMap<>();
    connectionResponse.put(ApiTestHelper.BROWSER_KEY, "3969ca217b");
    connectionResponse.put(ApiTestHelper.BROWSER_LOADER_VERSION, "248");
    connectionResponse.put(ApiTestHelper.JS_AGENT_LOADER, ApiTestHelper.LOADER);
    connectionResponse.put(ApiTestHelper.JS_AGENT_FILE, "js-agent.newrelic.com\nr-248.min.js");
    connectionResponse.put(ApiTestHelper.BEACON, "staging-beacon-2.newrelic.com");
    connectionResponse.put(ApiTestHelper.ERROR_BEACON, "staging-jserror.newrelic.com");
    connectionResponse.put(ApiTestHelper.APPLICATION_ID, 100L);
    // specifically not specified...should default to true
    // connectionResponse.put(RUM_ENABLED_KEY, false);
    ApiTestHelper.mockOutServiceManager(connectionResponse);
    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) HashMap(java.util.HashMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 48 with BasicRequestRootTracer

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

the class ApiTest method testNoticeThrowableWithParamsKeyTooLarge.

@Test
public void testNoticeThrowableWithParamsKeyTooLarge() 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(sb.toString(), "two");
        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(1, tx.getErrorAttributes().size());
        Assert.assertNull(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 49 with BasicRequestRootTracer

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

the class ApiTest method testGetBrowserTimingFooterWhenRUMDisabled.

@Test
public void testGetBrowserTimingFooterWhenRUMDisabled() throws Exception {
    Map<String, Object> connectionResponse = new HashMap<>();
    ApiTestHelper.mockOutServiceManager(connectionResponse);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    NewRelic.getBrowserTimingHeader();
    String browserTimingFooter = NewRelic.getBrowserTimingFooter();
    Assert.assertEquals("Incorrect header", "", browserTimingFooter);
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 50 with BasicRequestRootTracer

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

the class ApiTest method testGetBrowserTimingFooter.

@Test
public void testGetBrowserTimingFooter() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    Transaction tx = Transaction.getTransaction();
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    NewRelic.getBrowserTimingHeader();
    String browserTimingFooter = NewRelic.getBrowserTimingFooter();
    Assert.assertTrue("Incorrect footer.  Was " + browserTimingFooter + ", but expected it to start with " + getTimingFooterStart(), browserTimingFooter.startsWith(getTimingFooterStart()));
    tx.getTransactionActivity().tracerFinished(tracer, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

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