Search in sources :

Example 1 with NoOpTransaction

use of com.newrelic.agent.bridge.NoOpTransaction in project newrelic-java-agent by newrelic.

the class InstrumentationImpl method oldCreateSqlTracer.

// This code path is similar to the 3.16.1 and earlier tracer creation path. It is retained for use by legacy
// async instrumentation, including NAPS (Netty, Akka, Play, Scala) and async servlet instrumentation.
private ExitTracer oldCreateSqlTracer(TransactionActivity txa, Object invocationTarget, int signatureId, String metricName, int flags) {
    if (txa == null) {
        AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
        if (tokenAndRefCount != null && tokenAndRefCount.token != null) {
            // Fast path for scala instrumentation (and potentially others in the future)
            Transaction tx = Transaction.getTransaction(false);
            if (tx == null) {
                if (tokenAndRefCount.token.getTransaction() instanceof Transaction) {
                    tx = (Transaction) tokenAndRefCount.token.getTransaction();
                } else {
                    return null;
                }
            }
            txa = TransactionActivity.create(tx, Integer.MAX_VALUE);
            flags = flags | TracerFlags.ASYNC;
            ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
            MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
            Tracer tracer;
            if (TracerFlags.isRoot(flags)) {
                // Dispatcher || Async
                tracer = new OtherRootSqlTracer(txa, sig, invocationTarget, mnf, flags);
            } else if (overSegmentLimit(txa)) {
                logger.log(Level.FINEST, "Transaction has exceeded tracer segment limit. Returning ultralight sql tracer.");
                return UltraLightTracer.createClampedSegment(txa, sig);
            } else {
                tracer = new DefaultSqlTracer(txa, sig, invocationTarget, mnf, flags);
            }
            txa.tracerStarted(tracer);
            Tracer initiatingTracer = (Tracer) tokenAndRefCount.tracedMethod.getAndSet(tracer);
            tx.startFastAsyncWork(txa, initiatingTracer);
            return tracer;
        } else if (TracerFlags.isAsync(flags)) {
            txa = TransactionActivity.create(null, Integer.MAX_VALUE);
            return startTracer(txa, invocationTarget, signatureId, metricName, flags);
        }
    }
    // Avoid creating tracers for NoOpTransaction, etc.
    com.newrelic.agent.Transaction transaction = com.newrelic.agent.Transaction.getTransaction(TracerFlags.isDispatcher(flags));
    if (transaction == null) {
        return null;
    }
    try {
        if (!TracerFlags.isDispatcher(flags) && !transaction.isStarted()) {
            // if we're not in a transaction and this isn't a dispatcher tracer, bail before we create objects
            return null;
        }
        if (transaction.getTransactionActivity().isLeaf()) {
            return null;
        }
        ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
        return transaction.getTransactionState().getSqlTracer(transaction, invocationTarget, sig, metricName, flags);
    } catch (Throwable t) {
        logger.log(Level.FINEST, t, "createTracer({0}, {1}, {2}, {3})", invocationTarget, signatureId, metricName, flags);
        return null;
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Transaction(com.newrelic.agent.Transaction) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer)

Example 2 with NoOpTransaction

use of com.newrelic.agent.bridge.NoOpTransaction in project newrelic-java-agent by newrelic.

the class CircuitBreakerServiceFunctionalTest method aTransaction.

@Trace(dispatcher = true)
private void aTransaction(boolean breakerTripped) {
    Transaction transaction = NewRelic.getAgent().getTransaction();
    InstrumentationImpl impl = new InstrumentationImpl(Agent.LOG);
    if (breakerTripped) {
        ExitTracer createdTracer = impl.createTracer(null, 0, "metricName", TracerFlags.DISPATCHER);
        Assert.assertNull(createdTracer);
        Assert.assertTrue(transaction instanceof NoOpTransaction);
    } else {
        Assert.assertTrue(transaction instanceof TransactionApiImpl);
    }
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) Transaction(com.newrelic.api.agent.Transaction) InstrumentationImpl(com.newrelic.agent.instrumentation.InstrumentationImpl) TransactionApiImpl(com.newrelic.agent.TransactionApiImpl) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) Trace(com.newrelic.api.agent.Trace)

Example 3 with NoOpTransaction

use of com.newrelic.agent.bridge.NoOpTransaction in project newrelic-java-agent by newrelic.

the class InstrumentationImpl method oldCreateTracer.

// This code path is similar to the 3.16.1 and earlier tracer creation path. It is retained for use by legacy async
// instrumentation: Play1 and async servlet 3.0 instrumentation. The key difference from the "fast path" is that
// this path switches on the TransactionState during creation.
private ExitTracer oldCreateTracer(TransactionActivity txa, Object invocationTarget, int signatureId, String metricName, int flags) {
    // oldCreateTracer behavior below.
    if (txa == null) {
        AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
        if (tokenAndRefCount != null && tokenAndRefCount.token != null) {
            // Fast path for scala instrumentation (and potentially others in the future)
            Transaction tx = Transaction.getTransaction(false);
            if (tx == null) {
                if (tokenAndRefCount.token.getTransaction() instanceof Transaction) {
                    tx = (Transaction) tokenAndRefCount.token.getTransaction();
                } else {
                    return null;
                }
            }
            txa = TransactionActivity.create(tx, Integer.MAX_VALUE);
            flags = flags | TracerFlags.ASYNC;
            ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
            MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
            Tracer tracer;
            if (TracerFlags.isRoot(flags)) {
                // Dispatcher || Async
                tracer = new OtherRootTracer(txa, sig, invocationTarget, mnf, flags);
            } else {
                tracer = new DefaultTracer(txa, sig, invocationTarget, mnf, flags);
            }
            txa.tracerStarted(tracer);
            Tracer initiatingTracer = (Tracer) tokenAndRefCount.tracedMethod.getAndSet(tracer);
            tx.startFastAsyncWork(txa, initiatingTracer);
            return noticeTracer(signatureId, flags, tracer);
        } else if (TracerFlags.isAsync(flags)) {
            txa = TransactionActivity.create(null, Integer.MAX_VALUE);
            return startTracer(txa, invocationTarget, signatureId, metricName, flags);
        }
    }
    // Avoid creating tracers for NoOpTransaction, etc.
    com.newrelic.agent.Transaction transaction = com.newrelic.agent.Transaction.getTransaction(TracerFlags.isDispatcher(flags));
    if (transaction == null) {
        return null;
    }
    try {
        if (!TracerFlags.isDispatcher(flags) && !transaction.isStarted()) {
            // if we're not in a transaction and this isn't a dispatcher tracer, bail before we create objects
            return noticeTracer(signatureId, flags, null);
        }
        if (transaction.getTransactionActivity().isLeaf()) {
            return null;
        }
        ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
        return transaction.getTransactionState().getTracer(transaction, invocationTarget, sig, metricName, flags);
    } catch (Throwable t) {
        logger.log(Level.FINEST, t, "createTracer({0}, {1}, {2}, {3})", invocationTarget, signatureId, metricName, flags);
        return null;
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Transaction(com.newrelic.agent.Transaction) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 4 with NoOpTransaction

use of com.newrelic.agent.bridge.NoOpTransaction in project newrelic-java-agent by newrelic.

the class AgentImplTest method testAsyncTracerShouldNotStartTxn.

@Test
public void testAsyncTracerShouldNotStartTxn() {
    TransactionActivity txa = TransactionActivity.create(null, 0);
    ClassMethodSignature sig = new ClassMethodSignature("class", "method", "methodDesc");
    OtherRootTracer tracer = new OtherRootTracer(txa, sig, null, null, TracerFlags.ASYNC, System.nanoTime());
    txa.tracerStarted(tracer);
    Transaction txn = agentImpl.getTransaction();
    Assert.assertTrue(txn instanceof NoOpTransaction);
    Assert.assertFalse(txn instanceof com.newrelic.agent.Transaction);
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Transaction(com.newrelic.agent.bridge.Transaction) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Aggregations

NoOpTransaction (com.newrelic.agent.bridge.NoOpTransaction)4 ExitTracer (com.newrelic.agent.bridge.ExitTracer)3 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)3 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 Transaction (com.newrelic.agent.Transaction)2 AgentBridge (com.newrelic.agent.bridge.AgentBridge)2 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)2 Tracer (com.newrelic.agent.tracers.Tracer)2 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)2 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)2 TransactionApiImpl (com.newrelic.agent.TransactionApiImpl)1 Transaction (com.newrelic.agent.bridge.Transaction)1 InstrumentationImpl (com.newrelic.agent.instrumentation.InstrumentationImpl)1 Trace (com.newrelic.api.agent.Trace)1 Transaction (com.newrelic.api.agent.Transaction)1 Test (org.junit.Test)1