Search in sources :

Example 26 with DefaultTracer

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

the class TransactionTest method createBasicTracer.

private DefaultTracer createBasicTracer(String id) {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), id, "()V");
    return new DefaultTracer(tx, sig, this, new SimpleMetricNameFormat("Custom/myname" + id));
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 27 with DefaultTracer

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

the class SegmentTest method testExclusiveTime.

@Test
public void testExclusiveTime() throws InterruptedException {
    DefaultTracer root = (DefaultTracer) makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    final com.newrelic.agent.bridge.TracedActivity tracedActivity = AgentBridge.getAgent().getTransaction().createAndStartTracedActivity();
    DefaultTracer underlyingTracer = (DefaultTracer) tracedActivity.getTracedMethod();
    Thread.sleep(10);
    tracedActivity.end();
    // Assuming the exclusive duration of the tracedActivity tracer is correct, verify the parent's exclusive
    // duration is calculated correctly
    root.performFinishWork(root.getStartTime() + 100, Opcodes.ARETURN, null);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertEquals(100, root.getExclusiveDuration());
    assertTrue(underlyingTracer.getExclusiveDuration() >= TimeUnit.MILLISECONDS.toNanos(10));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) TracedActivity(com.newrelic.agent.bridge.TracedActivity) Test(org.junit.Test)

Example 28 with DefaultTracer

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

the class SegmentTest method testExclusiveTimeAsync.

@Test
public void testExclusiveTimeAsync() throws InterruptedException {
    DefaultTracer root = (DefaultTracer) makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
    Thread finishThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            segment.end();
        }
    });
    finishThread.start();
    root.performFinishWork(root.getStartTime() + 100, Opcodes.ARETURN, null);
    finishThread.join();
    // exclusive duration of async tracedActivity tracer should not affect root tracer's exclusive duration
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertEquals(100, root.getExclusiveDuration());
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Test(org.junit.Test)

Example 29 with DefaultTracer

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

the class TransactionAsyncUtility method createDefaultTracer.

// Create a Tracer for tests that require one.
public static DefaultTracer createDefaultTracer(String methodName) {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("MyClass", methodName, "()V");
    DefaultTracer brrt = new DefaultTracer(tx, sig, new Object(), new SimpleMetricNameFormat("Custom/" + methodName));
    return brrt;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 30 with DefaultTracer

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

the class RequestUriConfigTests method startTracer.

private DefaultTracer startTracer() throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    DefaultTracer tracer = new OtherRootTracer(tx, sig, statement, new SimpleMetricNameFormat("metric", "segment", "some uri")) {

        @Override
        public long getDuration() {
            return 100000;
        }
    };
    tx.getTransactionActivity().tracerStarted(tracer);
    return tracer;
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Aggregations

DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)46 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)24 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)20 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)19 Transaction (com.newrelic.agent.Transaction)17 Tracer (com.newrelic.agent.tracers.Tracer)16 Test (org.junit.Test)14 TransactionData (com.newrelic.agent.TransactionData)6 ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)6 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)6 SqlTraceConfig (com.newrelic.agent.config.SqlTraceConfig)5 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)5 JSONObject (org.json.simple.JSONObject)5 MockDispatcher (com.newrelic.agent.MockDispatcher)4 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)4 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)4 HashMap (java.util.HashMap)4 TransactionActivity (com.newrelic.agent.TransactionActivity)3 ExitTracer (com.newrelic.agent.bridge.ExitTracer)3 ServerProp (com.newrelic.agent.config.ServerProp)3