Search in sources :

Example 1 with PriorityTransactionName

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);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) SpanProxy(com.newrelic.agent.tracing.SpanProxy) Tracer(com.newrelic.agent.tracers.Tracer) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Random(java.util.Random) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Collection(java.util.Collection) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with PriorityTransactionName

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);
}
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 3 with PriorityTransactionName

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||"));
}
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 4 with PriorityTransactionName

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

Example 5 with PriorityTransactionName

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

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