Search in sources :

Example 6 with PriorityTransactionName

use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.

the class BrowserConfigTest method testFooterNoCaptureParams.

@Test
public void testFooterNoCaptureParams() 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);
    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);
    Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
    // The value looks something like this but with no line breaks:
    // <script type="text/javascript">window.NREUM||(NREUM={});NREUM.info={
    // "applicationID":"45047","applicationTime":4045,"beacon":"staging-beacon-2.newrelic.com","queueTime":0,
    // "licenseKey":"3969ca217b","transactionName":"DxIJAw==","agent":"js-agent.newrelic.com\nr-248.min.js",
    // "errorBeacon":"staging-jserror.newrelic.com"}</script>
    String value = beaconConfig.getBrowserTimingFooter(bts);
    List<String> matched = new ArrayList<>(15);
    checkFooter(value, matched);
    List<String> expectedFooterProperties = Arrays.asList(EXPECTED_FOOTER_PROPERTIES);
    checkStrings(value, expectedFooterProperties, 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 7 with PriorityTransactionName

use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.

the class BrowserConfigTest method testFooterCaptureParamsNoParams.

@Test
public void testFooterCaptureParamsNoParams() 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);
    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);
    List<String> expectedFooterProperties = Arrays.asList(EXPECTED_FOOTER_PROPERTIES);
    checkStrings(value, expectedFooterProperties, 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 8 with PriorityTransactionName

use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.

the class BrowserTransactionStateTest method mockMultipleFootersTest.

private BrowserTransactionState mockMultipleFootersTest(boolean allowMultipleFooters) {
    PriorityTransactionName ptn = PriorityTransactionName.create("/en/betting/Football", null, TransactionNamePriority.CUSTOM_HIGH);
    AgentConfig agentConfig = Mockito.mock(AgentConfig.class);
    BrowserMonitoringConfig bmConfig = Mockito.mock(BrowserMonitoringConfig.class);
    Mockito.when(bmConfig.isAllowMultipleFooters()).thenReturn(allowMultipleFooters);
    Mockito.when(agentConfig.getBrowserMonitoringConfig()).thenReturn(bmConfig);
    Mockito.when(tx.isInProgress()).thenReturn(true);
    Mockito.when(tx.isIgnore()).thenReturn(false);
    Mockito.when(tx.getApplicationName()).thenReturn("Test");
    Mockito.when(tx.getPriorityTransactionName()).thenReturn(ptn);
    Mockito.when(tx.getAgentConfig()).thenReturn(agentConfig);
    Mockito.doNothing().when(tx).freezeTransactionName();
    long durationInNanos = TimeUnit.NANOSECONDS.convert(200L, TimeUnit.MILLISECONDS);
    Mockito.when(tx.getRunningDurationInNanos()).thenReturn(durationInNanos);
    final BrowserConfig bConfig = Mockito.mock(BrowserConfig.class);
    BrowserTransactionState bts = new BrowserTransactionStateImpl(tx) {

        @Override
        protected BrowserConfig getBeaconConfig() {
            return bConfig;
        }
    };
    Mockito.when(bConfig.getBrowserTimingHeader()).thenReturn("header");
    Mockito.when(bConfig.getBrowserTimingFooter(bts)).thenReturn("footer");
    Mockito.when(bConfig.getBrowserTimingFooter(eq(bts), anyString())).thenReturn("footerWithNonce");
    return bts;
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) BrowserMonitoringConfig(com.newrelic.agent.config.BrowserMonitoringConfig) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName)

Example 9 with PriorityTransactionName

use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.

the class TraceAnnotationTest method testCallAsyncAnnotatedThreadInsideOfTxnMultiThreaded.

/* Case 4: @Trace(async = true), multithreaded with a started Transaction */
@Test
public void testCallAsyncAnnotatedThreadInsideOfTxnMultiThreaded() throws InterruptedException {
    Transaction.clearTransaction();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicBoolean metricsAssertionsPassed = new AtomicBoolean(false);
    // AgentBridge getTransaction call should return null if no Transaction exists in ThreadLocal
    Assert.assertNull(AgentBridge.getAgent().getTransaction(false));
    // Transaction listener which will only countdown the latch when a specific txn finishes
    ServiceFactory.getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            PriorityTransactionName ptn = transactionData.getTransaction().getPriorityTransactionName();
            String txnMetric1 = "Java/test.newrelic.test.agent.TraceAnnotationTest$AsyncAnnotatedThreadInsideOfTxn/run";
            String txnMetric2 = "Java/test.newrelic.test.agent.TraceAnnotationTest/callAsyncAnnotatedThreadInsideOfTxnMultiThreaded";
            Map<String, StatsBase> scopedStatsMap = transactionStats.getScopedStats().getStatsMap();
            if (ptn.getPartialName().equals("/MyCategory/TracedAsyncTxn")) {
                try {
                    Assert.assertTrue("The following metric should exist: " + txnMetric1, scopedStatsMap.containsKey(txnMetric1));
                    Assert.assertTrue("The following metric should exist: " + txnMetric2, scopedStatsMap.containsKey(txnMetric2));
                    metricsAssertionsPassed.set(true);
                } catch (Throwable t) {
                    metricsAssertionsPassed.set(false);
                    t.printStackTrace();
                } finally {
                    latch.countDown();
                }
            }
        }
    });
    callAsyncAnnotatedThreadInsideOfTxnMultiThreaded();
    latch.await();
    Assert.assertTrue("Metric assertions didn't pass", metricsAssertionsPassed.get());
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionStats(com.newrelic.agent.stats.TransactionStats) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) TransactionData(com.newrelic.agent.TransactionData) CountDownLatch(java.util.concurrent.CountDownLatch) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with PriorityTransactionName

use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.

the class ApiTest method testGetBrowserTimingFooterNoHeader.

@Test
public void testGetBrowserTimingFooterNoHeader() 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);
    String browserTimingFooter = NewRelic.getBrowserTimingFooter();
    Assert.assertEquals("Incorrect header", "", browserTimingFooter);
    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

PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)26 Test (org.junit.Test)21 Transaction (com.newrelic.agent.Transaction)19 TransactionNamePriority (com.newrelic.agent.bridge.TransactionNamePriority)14 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)14 ArrayList (java.util.ArrayList)7 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)3 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)2 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NewRelicIgnoreTransaction (test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction)2 TransactionData (com.newrelic.agent.TransactionData)1 TransactionListener (com.newrelic.agent.TransactionListener)1 BrowserMonitoringConfig (com.newrelic.agent.config.BrowserMonitoringConfig)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1