Search in sources :

Example 61 with BasicRequestRootTracer

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

the class TransactionTest method testDisplayHostAttribute.

@Test
public void testDisplayHostAttribute() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> values = new HashMap<>();
    values.put("display_name", "onetwothree");
    configMap.put("process_host", values);
    createServiceManager(configMap);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    Thread.sleep(10);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    finishTransaction(tx, rootTracer);
    assertEquals(3, tx.getAgentAttributes().size());
    String actualDisplayName = (String) tx.getAgentAttributes().get("host.displayName");
    assertNotNull(actualDisplayName);
    assertEquals("onetwothree", actualDisplayName);
    assertNotNull(tx.getAgentAttributes().get("jvm.thread_name"));
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 62 with BasicRequestRootTracer

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

the class TransactionTest method checkRunningDuration.

@Test
public void checkRunningDuration() throws Exception {
    createServiceManager(createConfigMap());
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    long firstTime = tx.getRunningDurationInNanos();
    Thread.sleep(2);
    finishTransaction(tx, rootTracer);
    long endTime = tx.getRunningDurationInNanos();
    assertTrue(endTime > firstTime);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 63 with BasicRequestRootTracer

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

the class TransactionTest method addUserParams.

@Test
public void addUserParams() 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);
    tx.getUserAttributes().put("key1", "value1");
    finishTransaction(tx, rootTracer);
    Long cpuTime = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    assertNotNull(cpuTime);
    assertTrue(cpuTime > 0);
    assertEquals(2, tx.getAgentAttributes().size());
    assertNotNull(tx.getAgentAttributes().get("jvm.thread_name"));
    assertEquals(1, tx.getUserAttributes().size());
    assertEquals("value1", tx.getUserAttributes().get("key1"));
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 64 with BasicRequestRootTracer

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

the class TransactionTest method recordCpuAndGCTimeWithLegacyIsNotReported.

@Test
public void recordCpuAndGCTimeWithLegacyIsNotReported() 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);
    tx.addTotalCpuTimeForLegacy(TransactionActivity.NOT_REPORTED);
    rootTracer.finish(Opcodes.ARETURN, null);
    tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
    Long cpuTime = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
    // should not be reported
    assertNull(cpuTime);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 65 with BasicRequestRootTracer

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

the class TransactionTest method testInstanceNameAttribute.

@Test
public void testInstanceNameAttribute() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    configMap.put("instance_name", "MyInstanceName");
    createServiceManager(configMap);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    Thread.sleep(10);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    finishTransaction(tx, rootTracer);
    assertEquals(3, tx.getAgentAttributes().size());
    String actualInstanceName = (String) tx.getAgentAttributes().get("process.instanceName");
    assertNotNull(actualInstanceName);
    assertEquals("MyInstanceName", actualInstanceName);
    assertNotNull(tx.getAgentAttributes().get("jvm.thread_name"));
    configMap = createConfigMap();
    createServiceManager(configMap);
    Transaction.clearTransaction();
    tx = Transaction.getTransaction();
    rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    Thread.sleep(10);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    finishTransaction(tx, rootTracer);
    assertEquals(2, tx.getAgentAttributes().size());
    actualInstanceName = (String) tx.getAgentAttributes().get("process.instanceName");
    assertNull(actualInstanceName);
    assertNotNull(tx.getAgentAttributes().get("jvm.thread_name"));
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

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