Search in sources :

Example 86 with Tracer

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

the class ExternalAsyncTest method verifyCpu.

@Override
public void verifyCpu(long minCpu) {
    super.verifyCpu(minCpu);
    Collection<Tracer> tracers = data.getTracers();
    for (Tracer current : tracers) {
        if (current instanceof TransactionActivityInitiator) {
            TransactionActivity txa = current.getTransactionActivity();
            if (txa.getRootTracer().getAgentAttribute("async_context").equals(ASYNC_TXA_NAME)) {
                Assert.assertEquals("External calls should have zero CPU time", 0L, txa.getTotalCpuTime());
            }
        }
    }
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) Tracer(com.newrelic.agent.tracers.Tracer) TransactionActivity(com.newrelic.agent.TransactionActivity)

Example 87 with Tracer

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

the class ExternalsForTransactionTest method testcheckExternalsTwo.

@Test
public void testcheckExternalsTwo() {
    // web
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/secondhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/secondhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    tracers.add(createTracer("External/secondhost/secondlib", "External/secondhost/secondlib/secondOp"));
    Collection<ExternalRequestImpl> actual = ExternalsForTransaction.checkExternals(true, stats, tracers);
    Assert.assertEquals(2, actual.size());
    Iterator<ExternalRequestImpl> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("External/myhost/mylib")) {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("mylib", impl.getLibrary());
            Assert.assertEquals("myOp", impl.getOperation());
        } else {
            Assert.assertEquals("secondhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("secondOp", impl.getOperation());
        }
    }
    // other
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allOther").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/secondhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/secondhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    tracers.add(createTracer("External/secondhost/secondlib", "External/secondhost/secondlib/secondOp"));
    actual = ExternalsForTransaction.checkExternals(false, stats, tracers);
    Assert.assertEquals(2, actual.size());
    it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("External/myhost/mylib")) {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("mylib", impl.getLibrary());
            Assert.assertEquals("myOp", impl.getOperation());
        } else {
            Assert.assertEquals("secondhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("secondOp", impl.getOperation());
        }
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 88 with Tracer

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

the class ExternalsForTransactionTest method testAddExternalsOneCall.

@Test
public void testAddExternalsOneCall() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    tracers.add(createTracer("External/myhost/secondlib", "External/myhost/secondlib/seconop"));
    ExternalsForTransaction exts = new ExternalsForTransaction();
    exts.addExternals(true, stats, tracers);
    Collection<ExternalRequest> actual = exts.getExternals();
    Assert.assertEquals(2, actual.size());
    Iterator<ExternalRequest> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("External/myhost/mylib")) {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("mylib", impl.getLibrary());
            Assert.assertEquals("myop", impl.getOperation());
        } else {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("seconop", impl.getOperation());
        }
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 89 with Tracer

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

the class ExternalsForTransactionTest method testcheckExternalsOne.

@Test
public void testcheckExternalsOne() {
    // web
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    Collection<ExternalRequestImpl> actual = ExternalsForTransaction.checkExternals(true, stats, tracers);
    Assert.assertEquals(1, actual.size());
    ExternalRequestImpl impl = actual.iterator().next();
    Assert.assertEquals(1, impl.getCount());
    Assert.assertEquals("myhost", impl.getHostname());
    Assert.assertEquals("mylib", impl.getLibrary());
    Assert.assertEquals("myOp", impl.getOperation());
    // other
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allOther").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myOp"));
    actual = ExternalsForTransaction.checkExternals(false, stats, tracers);
    Assert.assertEquals(1, actual.size());
    impl = actual.iterator().next();
    Assert.assertEquals(1, impl.getCount());
    Assert.assertEquals("myhost", impl.getHostname());
    Assert.assertEquals("mylib", impl.getLibrary());
    Assert.assertEquals("myOp", impl.getOperation());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 90 with Tracer

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

the class ExternalsForTransactionTest method testAddExternalsTwoCallsSameOperation.

@Test
public void testAddExternalsTwoCallsSameOperation() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    ExternalsForTransaction exts = new ExternalsForTransaction();
    exts.addExternals(true, stats, tracers);
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    exts.addExternals(true, stats, tracers);
    Collection<ExternalRequest> actual = exts.getExternals();
    Assert.assertEquals(1, actual.size());
    Iterator<ExternalRequest> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
        Assert.assertEquals(2, impl.getCount());
        Assert.assertEquals("myhost", impl.getHostname());
        Assert.assertEquals("mylib", impl.getLibrary());
        Assert.assertEquals("myop", impl.getOperation());
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

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