Search in sources :

Example 11 with BasicRequestRootTracer

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;
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Example 12 with BasicRequestRootTracer

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);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArrayList(java.util.ArrayList) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) Test(org.junit.Test)

Example 13 with BasicRequestRootTracer

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||"));
}
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) Test(org.junit.Test)

Example 14 with BasicRequestRootTracer

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);
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Example 15 with BasicRequestRootTracer

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);
}
Also used : PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArrayList(java.util.ArrayList) Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) 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