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