Search in sources :

Example 31 with Tracer

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

the class TransactionStateImplTest method tracerMetricName_Null.

@Test
public void tracerMetricName_Null() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude1", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, null, sig, null, simpleFlags);
    assertEquals(tracer, tx.getTransactionActivity().getLastTracer());
    assertEquals("Java/com.test.Dude/dude1", tracer.getMetricName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Example 32 with Tracer

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

the class TransactionStateImplTest method tracerMetricName.

@Test
public void tracerMetricName() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude4", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, new Object(), sig, "Test/${className}/dude4", TracerFlags.CUSTOM);
    assertEquals(tracer, tx.getTransactionActivity().getLastTracer());
    assertEquals("Test/java.lang.Object/dude4", tracer.getMetricName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Example 33 with Tracer

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

the class TransactionStateImplTest method tracerMetricName_NullInvocationTarget.

@Test
public void tracerMetricName_NullInvocationTarget() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude3", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, null, sig, "Test/${className}/dude3", getTracerFlags(false, false, true));
    assertEquals(tracer, tx.getTransactionActivity().getLastTracer());
    assertEquals("Test/com.test.Dude/dude3", tracer.getMetricName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Example 34 with Tracer

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

the class TransactionTest method testTracerLimit1.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimit1() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put("segment_limit", 3);
    createServiceManager(config);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    DefaultTracer t1 = createBasicTracer("one");
    tx.getTransactionActivity().tracerStarted(t1);
    DefaultTracer t2 = createBasicTracer("two");
    tx.getTransactionActivity().tracerStarted(t2);
    DefaultTracer t3 = createBasicTracer("three");
    tx.getTransactionActivity().tracerStarted(t3);
    DefaultTracer t4 = createBasicTracer("four");
    tx.getTransactionActivity().tracerStarted(t4);
    DefaultTracer t5 = createBasicTracer("five");
    tx.getTransactionActivity().tracerStarted(t5);
    tx.getTransactionActivity().tracerFinished(t5, 0);
    tx.getTransactionActivity().tracerFinished(t4, 0);
    tx.getTransactionActivity().tracerFinished(t3, 0);
    tx.getTransactionActivity().tracerFinished(t2, 0);
    tx.getTransactionActivity().tracerFinished(t1, 0);
    finishTransaction(tx, rootTracer);
    Set<TransactionActivity> done = tx.getFinishedChildren();
    assertEquals(1, done.size());
    TransactionActivity txa = done.iterator().next();
    List<Tracer> tracers = txa.getTracers();
    assertEquals(3, tracers.size());
    assertTrue(tracers.contains(t1));
    assertTrue(tracers.contains(t2));
    assertTrue(tracers.contains(t3));
    // Verify that we send up the segment_clamp supportability metric
    TransactionStats stats = txa.getTransactionStats();
    assertNotNull(stats);
    StatsImpl segmentClamp = (StatsImpl) stats.getUnscopedStats().getStatsMap().get(MetricNames.SUPPORTABILITY_TRANSACTION_SEGMENT_CLAMP);
    assertNotNull(segmentClamp);
    // The limit is 3 so the clamp will take effect at 4
    assertEquals(4, (int) segmentClamp.getTotal());
    // Should get incremented once for the tx
    assertEquals(1, segmentClamp.getCallCount());
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 35 with Tracer

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

the class TransactionTest method testCreatePayload.

@Test
public void testCreatePayload() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    configMap.put(AgentConfigImpl.DISTRIBUTED_TRACING, ImmutableMap.of("enabled", Boolean.TRUE));
    createServiceManager(configMap);
    Transaction.clearTransaction();
    Tracer dispatcherTracer = createDispatcherTracer(true);
    Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
    transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
    String spanId = "honkhonkhonk";
    DistributedTracePayloadImpl payload = transaction.createDistributedTracePayload(spanId);
    assertNotNull(payload);
    dispatcherTracer.finish(Opcodes.ARETURN, null);
    assertEquals("App", payload.parentType);
    assertEquals(spanId, payload.guid);
    // first 10 transactions should be sampled
    assertTrue(DistributedTraceUtil.isSampledPriority(payload.priority));
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Aggregations

Tracer (com.newrelic.agent.tracers.Tracer)263 Test (org.junit.Test)195 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)104 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)99 Transaction (com.newrelic.agent.Transaction)86 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)54 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)41 ExitTracer (com.newrelic.agent.bridge.ExitTracer)39 TokenImpl (com.newrelic.agent.TokenImpl)35 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)31 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)25 TransactionData (com.newrelic.agent.TransactionData)24 HashMap (java.util.HashMap)24 SqlTracer (com.newrelic.agent.tracers.SqlTracer)20 ArrayList (java.util.ArrayList)19 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)17 TransactionStats (com.newrelic.agent.stats.TransactionStats)16 MockRPMService (com.newrelic.agent.MockRPMService)15 JSONArray (org.json.simple.JSONArray)15 JSONObject (org.json.simple.JSONObject)14