Search in sources :

Example 21 with BasicRequestRootTracer

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

the class SqlTraceServiceTest method startDispatcherTracer.

private Tracer startDispatcherTracer(String appName) throws Exception {
    Transaction tx = Transaction.getTransaction();
    MockHttpRequest httpRequest = new MockHttpRequest();
    MockHttpResponse httpResponse = new MockHttpResponse();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    Tracer requestDispatcherTracer = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
    tx.getTransactionActivity().tracerStarted(requestDispatcherTracer);
    tx.setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, appName);
    return requestDispatcherTracer;
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Example 22 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer 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 23 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer 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 24 with BasicRequestRootTracer

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

the class ApiTest method testGetBrowserTimingFooterRUM4.

@Test
public void testGetBrowserTimingFooterRUM4() 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);
    ApiTestHelper.mockOutServiceManager(connectionResponse);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    NewRelic.getBrowserTimingHeader();
    String browserTimingFooter = NewRelic.getBrowserTimingFooter();
    Assert.assertTrue("Incorrect footer.  Was " + browserTimingFooter + " expected to start with " + getTimingFooterStart(), browserTimingFooter.startsWith(getTimingFooterStart()));
    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 25 with BasicRequestRootTracer

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

the class ApiTest method testGetBrowserTimingFooterWhenRUMEnabledNotSpecified.

@Test
public void testGetBrowserTimingFooterWhenRUMEnabledNotSpecified() 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);
    ApiTestHelper.mockOutServiceManager(connectionResponse);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    NewRelic.getBrowserTimingHeader();
    String browserTimingFooter = NewRelic.getBrowserTimingFooter();
    Assert.assertTrue("Incorrect footer.  Was " + browserTimingFooter + " expected to start with " + getTimingFooterStart(), browserTimingFooter.startsWith(getTimingFooterStart()));
    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)

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