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