use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method startDispatcherTracer.
private Tracer startDispatcherTracer(String appName, String uri) throws Exception {
Transaction tx = Transaction.getTransaction();
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setRequestURI(uri);
MockHttpResponse httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
BasicRequestRootTracer requestDispatcherTracer = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
Dispatcher dispatcher = requestDispatcherTracer.createDispatcher();
tx.getTransactionActivity().tracerStarted(requestDispatcherTracer);
tx.setDispatcher(dispatcher);
tx.setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, appName);
return requestDispatcherTracer;
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method testFooterWithNonce.
@Test
public void testFooterWithNonce() throws Exception {
setupManager(true, false);
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
tx.getTransactionActivity().tracerStarted(tracer);
TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
tx.setPriorityTransactionName(ptn);
tx.getUserAttributes().put("theInt", 11);
tx.getUserAttributes().put("theDouble", 11.22);
tx.getUserAttributes().put("theLong", 22L);
tx.getUserAttributes().put("theString", "abc123");
tx.getUserAttributes().put("theShort", Short.parseShort("1"));
Map<String, Object> beaconSettings = createBeaconSettings(true);
BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
String value = beaconConfig.getBrowserTimingFooter(bts, "ABC123");
List<String> matched = new ArrayList<>(2);
String expectedStartScript = "\n<script type=\"text/javascript\" nonce=\"ABC123\">" + BrowserFooter.FOOTER_JS_START;
Assert.assertTrue(value.startsWith(expectedStartScript));
matched.add(expectedStartScript);
Assert.assertTrue(value.endsWith(BrowserFooter.FOOTER_END));
matched.add(BrowserFooter.FOOTER_END);
final List<String> expectedFooterProperties = Arrays.asList(EXPECTED_FOOTER_PROPERTIES);
// The whole point to the tricky code in checkStrings(), above, is that these key:value
// pairs do not have to come back in the same order that they were added in, above.
final String[] USER_ATTRIBUTES = { "\"theInt\":11", "\"theDouble\":11.22", "\"theLong\":22", "\"theString\":\"abc123\"", "\"theShort\":1" };
final List<String> expectedUserAttributes = Arrays.asList(USER_ATTRIBUTES);
checkStringsAndUserParams(value, expectedFooterProperties, expectedUserAttributes, null, matched);
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method testRumDisableNoAgentFile.
@Test
public void testRumDisableNoAgentFile() throws Exception {
setupManager(false, false);
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
tx.getTransactionActivity().tracerStarted(tracer);
TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
tx.setPriorityTransactionName(ptn);
// off
try {
Map<String, Object> beaconSettings = createBeaconSettingsEmtpyAgentFile(false);
BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
beaconConfig.getBrowserTimingHeader();
Assert.fail("An exception should have been thrown when rum is disabled");
} catch (Exception e) {
// we should go into here
}
// back on
Map<String, Object> beaconSettings = createBeaconSettingsEmtpyAgentFile(true);
BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
Assert.assertTrue(beaconConfig.getBrowserTimingFooter(bts).startsWith("\n<script type=\"text/javascript\">window.NREUM||"));
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method createDispatcherTracer.
private BasicRequestRootTracer createDispatcherTracer() {
Transaction tx = Transaction.getTransaction();
MockHttpRequest httpRequest = new MockHttpRequest();
MockHttpResponse httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method testFooterCaptureAttsOneAndSsl.
@Test
public void testFooterCaptureAttsOneAndSsl() throws Exception {
setupManager(true, true);
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
tx.getTransactionActivity().tracerStarted(tracer);
TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
tx.setPriorityTransactionName(ptn);
tx.getUserAttributes().put("product", "daProduct");
Map<String, Object> beaconSettings = createBeaconSettings(true);
BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
String value = beaconConfig.getBrowserTimingFooter(bts);
List<String> matched = new ArrayList<>(15);
checkFooter(value, matched);
final ArrayList<String> expectedFooterProperties = new ArrayList<>();
expectedFooterProperties.addAll(Arrays.asList(EXPECTED_FOOTER_PROPERTIES));
expectedFooterProperties.add("\"sslForHttp\":true");
final String[] USER_ATTRIBUTES = { "\"product\":\"daProduct\"" };
final List<String> expectedUserAttributes = Arrays.asList(USER_ATTRIBUTES);
checkStringsAndUserParams(value, expectedFooterProperties, expectedUserAttributes, null, matched);
}
Aggregations