Search in sources :

Example 66 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class TransactionTest method recordCpuAndGCTime.

@Test
public void recordCpuAndGCTime() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    createServiceManager(configMap);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    Thread.sleep(40);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    rootTracer.finish(Opcodes.ARETURN, null);
    tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
    Long cpuTime = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    assertNotNull(cpuTime);
    assertTrue(cpuTime > 0);
    tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
    Long cpuTime2 = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    assertEquals(cpuTime, cpuTime2);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 67 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class TransactionTest method testTracerLimitAsync.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsync() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put("segment_limit", 3);
    createServiceManager(config);
    Object context1 = 1L;
    Object context2 = 2L;
    Object context3 = 3L;
    Object context4 = 4L;
    Object context5 = 5L;
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
    InitThread async1 = new InitThread(context1, context2, false);
    async1.start();
    async1.join();
    assertEquals(1, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    InitThread async2 = new InitThread(context2, context3, false);
    async2.start();
    async2.join();
    assertEquals(2, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    InitThread async3 = new InitThread(context3, context4, false);
    async3.start();
    async3.join();
    assertEquals(3, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    TransactionStats stats = tx.getOverLimitTxStatsforTesting();
    assertNull(stats);
    InitThread async4 = new InitThread(context4, context5, false);
    async4.start();
    async4.join();
    assertEquals(3, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    stats = tx.getOverLimitTxStatsforTesting();
    assertNotNull(stats);
    ResponseTimeStatsImpl theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
    assertNotNull(theStat);
    float initValue = theStat.getTotal();
    assertEquals(1, theStat.getCallCount());
    InitThread async5 = new InitThread(context5, null, false);
    async5.start();
    async5.join();
    assertEquals(3, tx.getFinishedChildren().size());
    assertEquals(1, tx.getRunningTransactionActivityCount());
    stats = tx.getOverLimitTxStatsforTesting();
    assertNotNull(stats);
    theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
    assertNotNull(theStat);
    assertTrue(theStat.getTotal() > initValue);
    assertEquals(2, theStat.getCallCount());
    finishTransaction(tx, rootTracer);
    assertEquals(4, tx.getFinishedChildren().size());
    assertEquals(0, tx.getRunningTransactionActivityCount());
    // here all of the stats should have been merged in - not just the TXAs that were dropped
    stats = tx.getOverLimitTxStatsforTesting();
    assertNotNull(stats);
    theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
    assertNotNull(theStat);
    assertTrue(theStat.getTotal() > initValue);
    assertEquals(5, theStat.getCallCount());
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 68 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method testCustomAttributesInTransaction.

@Test
public void testCustomAttributesInTransaction() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        manager.setAttributesService(new AttributesService());
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        impl.addCustomParameter("abc.thread", "1");
        impl.addCustomParameter("request.many", "1");
        impl.addCustomParameter("message.many", "1");
        impl.addCustomParameter("message.bool", true);
        Map<String, Object> customParamMap = new HashMap<>();
        customParamMap.put("key1", "val1");
        customParamMap.put("key2", 2);
        customParamMap.put("key3", new HashMap<>());
        customParamMap.put("key4", true);
        customParamMap.put("key5", null);
        impl.addCustomParameters(customParamMap);
        Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many", "key1", "key2", "key4", "message.bool");
        verifyOutput(t.getUserAttributes(), expected);
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : TransactionService(com.newrelic.agent.TransactionService) HashMap(java.util.HashMap) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory) Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test)

Example 69 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest 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 70 with BasicRequestRootTracer

use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method shouldTruncateLongAttributeValues.

@Test
public void shouldTruncateLongAttributeValues() {
    try {
        Map<String, Object> settings = new HashMap<>();
        settings.put("app_name", APP_NAME);
        manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
        manager.setTransactionService(new TransactionService());
        manager.setTransactionTraceService(new TransactionTraceService());
        manager.setAttributesService(new AttributesService());
        Transaction t = Transaction.getTransaction();
        BasicRequestRootTracer tracer = createDispatcherTracer();
        t.getTransactionActivity().tracerStarted(tracer);
        NewRelicApiImplementation impl = new NewRelicApiImplementation();
        impl.addCustomParameter(makeLongString("ignored-key-too-long"), "vv");
        String valueVeryLong = makeLongString("v2");
        impl.addCustomParameter("truncated-single-value", valueVeryLong);
        Map<String, Object> customParamMap = new HashMap<>();
        customParamMap.put(makeLongString("ignored-key-too-long-also"), "vx");
        customParamMap.put("truncated-map-value", makeLongString("v4"));
        impl.addCustomParameters(customParamMap);
        Set<String> expected = Sets.newHashSet("truncated-single-value", "truncated-map-value");
        Map<String, Object> attribs = t.getUserAttributes();
        Assert.assertEquals(expected, attribs.keySet());
        Assert.assertEquals(255, attribs.get("truncated-single-value").toString().length());
        Assert.assertNotEquals(255, valueVeryLong.length());
        Assert.assertEquals(255, attribs.get("truncated-map-value").toString().length());
        Assert.assertNotEquals(255, customParamMap.get("truncated-map-value"));
    } finally {
        Transaction.clearTransaction();
    }
}
Also used : ConfigServiceFactory(com.newrelic.agent.config.ConfigServiceFactory) TransactionService(com.newrelic.agent.TransactionService) Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) NewRelicApiImplementation(com.newrelic.api.agent.NewRelicApiImplementation) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) 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