use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.
the class TransactionDataTestBuilder method build.
public TransactionData build() {
when(tx.getRootTracer()).thenReturn(tracer);
if (synJobId == null || synMonitorId == null || synResourceId == null) {
when(tx.isSynthetic()).thenReturn(false);
} else {
when(tx.isSynthetic()).thenReturn(true);
}
when(tx.getGuid()).thenReturn("guid");
Dispatcher mockDispatcher = mock(Dispatcher.class);
when(mockDispatcher.getUri()).thenReturn(requestUri);
when(mockDispatcher.isWebTransaction()).thenReturn(dispatcher == null ? true : dispatcher.isWebTransaction());
when(tx.getDispatcher()).thenReturn(mockDispatcher);
if (throwable != null) {
when(tx.getThrowable()).thenReturn(new TransactionThrowable(throwable, expectedError, null));
}
PriorityTransactionName priorityTransactionName = mock(PriorityTransactionName.class);
when(priorityTransactionName.getName()).thenReturn(frontendMetricName);
when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
Map<String, Map<String, String>> prefixed = new HashMap<>();
prefixed.put("request.parameters.", requestParams);
when(tx.getPrefixedAgentAttributes()).thenReturn(prefixed);
when(tx.getUserAttributes()).thenReturn(userParams);
when(tx.getAgentAttributes()).thenReturn(agentParams);
when(tx.getErrorAttributes()).thenReturn(errorParams);
when(tx.getIntrinsicAttributes()).thenReturn(intrinsics);
when(tx.isIgnore()).thenReturn(false);
when(tx.getStatus()).thenReturn(responseStatus);
when(tx.getStatusMessage()).thenReturn(statusMessage);
when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
when(tx.getSpanProxy()).thenReturn(new SpanProxy());
ErrorServiceImpl errorService = mock(ErrorServiceImpl.class);
IRPMService rpmService = mock(IRPMService.class);
when(rpmService.getApplicationName()).thenReturn(appName);
when(rpmService.getErrorService()).thenReturn(errorService);
when(tx.getRPMService()).thenReturn(rpmService);
when(tx.getAgentConfig()).thenReturn(agentConfig);
when(tx.getWallClockStartTimeMs()).thenReturn(startTime);
if (slowQueryListener != null) {
when(tx.getSlowQueryListener(anyBoolean())).thenReturn(slowQueryListener);
}
when(tx.getTracers()).thenReturn(tracers);
CrossProcessTransactionState crossProcessTransactionState = mock(CrossProcessTransactionState.class);
when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
when(crossProcessTransactionState.getTripId()).thenReturn("tripId");
InboundHeaderState ihs = mock(InboundHeaderState.class);
when(ihs.getSyntheticsJobId()).thenReturn(synJobId);
when(ihs.getSyntheticsMonitorId()).thenReturn(synMonitorId);
when(ihs.getSyntheticsResourceId()).thenReturn(synResourceId);
when(ihs.getSyntheticsVersion()).thenReturn(HeadersUtil.SYNTHETICS_MIN_VERSION);
when(tx.getInboundHeaderState()).thenReturn(ihs);
TransactionTimer timer = new TransactionTimer(tracer.getStartTime());
timer.markTransactionActivityAsDone(tracer.getEndTime(), tracer.getDuration());
timer.markTransactionAsDone();
when(tx.getTransactionTimer()).thenReturn(timer);
// when(tx.getApplicationName()).thenReturn(appName);
Set<TransactionActivity> activities = new HashSet<>();
for (Map.Entry<Long, Collection<Duration>> entry : threadIdToDuration.asMap().entrySet()) {
for (Duration duration : entry.getValue()) {
TransactionActivity activity = mock(TransactionActivity.class);
when(activity.getThreadId()).thenReturn(entry.getKey());
Tracer rootTracer = mock(Tracer.class);
when(rootTracer.getStartTime()).thenReturn(duration.startTime);
when(rootTracer.getEndTime()).thenReturn(duration.endTime);
when(activity.getRootTracer()).thenReturn(rootTracer);
activities.add(activity);
}
}
when(tx.getFinishedChildren()).thenReturn(activities);
if (includeDistributedTracePayload) {
SpanProxy spanProxy = mock(SpanProxy.class);
DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload("abc", "def", "def", new Random().nextFloat());
when(spanProxy.getInboundDistributedTracePayload()).thenReturn(payload);
when(tx.getSpanProxy()).thenReturn(spanProxy);
}
return new TransactionData(tx, 0);
}
use of com.newrelic.agent.transaction.PriorityTransactionName 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.transaction.PriorityTransactionName 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.transaction.PriorityTransactionName 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);
}
use of com.newrelic.agent.transaction.PriorityTransactionName in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method testFooterCaptureAtts.
@Test
public void testFooterCaptureAtts() 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);
Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
String value = beaconConfig.getBrowserTimingFooter(bts);
List<String> matched = new ArrayList<>(15);
checkFooter(value, matched);
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);
}
Aggregations