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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations