Search in sources :

Example 6 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class HttpClientRequestBase_Instrumentation method handleException.

@Trace(async = true)
public void handleException(Throwable t) {
    if (segment != null) {
        if (t instanceof UnknownHostException) {
            VertxCoreUtil.reportUnknownHost(segment);
        }
        final Token token = segment.getTransaction().getToken();
        segment.end();
        token.linkAndExpire();
    }
    Weaver.callOriginal();
}
Also used : UnknownHostException(java.net.UnknownHostException) Token(com.newrelic.api.agent.Token) Trace(com.newrelic.api.agent.Trace)

Example 7 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TraceAnnotationTest method callAsyncAnnotatedThreadOutsideOfTxnMultiThreaded.

// Don't start a transaction with @Trace(dispatcher = true)
private void callAsyncAnnotatedThreadOutsideOfTxnMultiThreaded() throws InterruptedException {
    Token token = NewRelic.getAgent().getTransaction().getToken();
    CountDownLatch latch = new CountDownLatch(1);
    // Outside of a txn, getToken should return NoOpToken
    Assert.assertEquals("NewRelic.getAgent().getTransaction().getToken() should return NoOpToken", com.newrelic.agent.bridge.NoOpToken.class, token.getClass());
    // AgentBridge getTransaction call should return null if no Transaction exists in ThreadLocal
    Assert.assertNull(AgentBridge.getAgent().getTransaction(false));
    AsyncAnnotatedThreadOutsideOfTxn asyncAnnotatedThreadOutsideOfTxn = new AsyncAnnotatedThreadOutsideOfTxn(latch);
    asyncAnnotatedThreadOutsideOfTxn.start();
    latch.await();
}
Also used : Token(com.newrelic.api.agent.Token) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class FlyweightTracerTest method getTokenFromFlyweight.

@Trace(excludeFromTransactionTrace = true, leaf = true)
private void getTokenFromFlyweight() {
    // When you are in a flyweight method you should not be allowed to get a token for async linking due to the
    // fact that we have no real parent tracer to tie the token to. We can revisit this in the future if need be
    // but it would require a significant number of changes to the agent
    Token token = AgentBridge.getAgent().getTransaction().getToken();
    Assert.assertNotNull(token);
    Assert.assertFalse(token.isActive());
    Assert.assertTrue(token instanceof NoOpToken);
}
Also used : Token(com.newrelic.api.agent.Token) NoOpToken(com.newrelic.agent.bridge.NoOpToken) NoOpToken(com.newrelic.agent.bridge.NoOpToken) Trace(com.newrelic.api.agent.Trace)

Example 9 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TransactionAsyncTimeoutTest method testRegisterTwiceRunOnce.

@Test
public void testRegisterTwiceRunOnce() throws Exception {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    final Token t1 = tx.getToken();
    final Token t2 = tx.getToken();
    tx.getTransactionActivity().tracerFinished(rootTracer, 0);
    Assert.assertNull(data);
    Assert.assertNull(stats);
    Thread a1 = new Thread() {

        @Override
        public void run() {
            Transaction.clearTransaction();
            Transaction oldTx = Transaction.getTransaction();
            Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one" + t1.toString());
            oldTx.getTransactionActivity().tracerStarted(rootTracer);
            t1.link();
            Transaction newTx = Transaction.getTransaction();
            Assert.assertTrue(oldTx != newTx);
            newTx.getTransactionActivity().tracerFinished(rootTracer, 0);
            t1.expire();
        }
    };
    a1.start();
    a1.join();
    Thread.sleep(1000);
    ServiceFactory.getTransactionService().processQueue();
    // wait for async token timeouts to complete
    Thread.sleep(500);
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(2, tx.getFinishedChildren().size());
    assertTokenMetricCounts(2, 1, 1, 0, 1);
}
Also used : Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) Token(com.newrelic.api.agent.Token) Test(org.junit.Test)

Example 10 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class TransactionAsyncTimeoutTest method testRegisterTwiceNoExpires.

@Test
public void testRegisterTwiceNoExpires() throws Exception {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    final Token t1 = tx.getToken();
    final Token t2 = tx.getToken();
    tx.getTransactionActivity().tracerFinished(rootTracer, 0);
    Assert.assertNull(data);
    Assert.assertNull(stats);
    Thread a1 = new Thread() {

        @Override
        public void run() {
            Transaction.clearTransaction();
            Transaction oldTx = Transaction.getTransaction();
            Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "one" + t1.toString());
            oldTx.getTransactionActivity().tracerStarted(rootTracer);
            t1.link();
            Transaction newTx = Transaction.getTransaction();
            Assert.assertTrue(oldTx != newTx);
            Token t3 = newTx.getToken();
            newTx.getTransactionActivity().tracerFinished(rootTracer, 0);
        // no expire here
        }
    };
    a1.start();
    a1.join();
    Thread.sleep(1000);
    ServiceFactory.getTransactionService().processQueue();
    // wait for async token timeouts to complete
    Thread.sleep(500);
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(2, tx.getFinishedChildren().size());
    assertTokenMetricCounts(3, 0, 3, 0, 1);
}
Also used : Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) Token(com.newrelic.api.agent.Token) Test(org.junit.Test)

Aggregations

Token (com.newrelic.api.agent.Token)24 Trace (com.newrelic.api.agent.Trace)8 Transaction (com.newrelic.agent.Transaction)4 Tracer (com.newrelic.agent.tracers.Tracer)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 TransactionActivity (com.newrelic.agent.TransactionActivity)1 NoOpToken (com.newrelic.agent.bridge.NoOpToken)1 Transaction (com.newrelic.agent.bridge.Transaction)1 WeavePackageType (com.newrelic.api.agent.weaver.internal.WeavePackageType)1 MuleUtils (com.nr.agent.instrumentation.mule3.MuleUtils)1 Job (gov.cms.ab2d.common.model.Job)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1 FhirVersion (gov.cms.ab2d.fhir.FhirVersion)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1