Search in sources :

Example 1 with MetricNameFormat

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

the class TransactionStateImpl method getTracer.

/**
 * Get tracer for weaved code and XML instrumentation (no tracer factory)
 */
@Override
public Tracer getTracer(Transaction tx, final Object invocationTarget, final ClassMethodSignature sig, final String metricName, final int flags) {
    TransactionActivity activity = tx.getTransactionActivity();
    if (tx.isIgnore() || activity.isTracerStartLocked()) {
        return null;
    }
    Tracer tracer;
    final MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
    if (TracerFlags.isDispatcher(flags)) {
        tracer = new OtherRootTracer(tx, sig, invocationTarget, mnf);
    } else {
        tracer = new DefaultTracer(tx, sig, invocationTarget, mnf, flags);
    }
    return tracerStarted(tx, sig, tracer);
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SkipTracer(com.newrelic.agent.tracers.SkipTracer) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 2 with MetricNameFormat

use of com.newrelic.agent.tracers.metricname.MetricNameFormat 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 3 with MetricNameFormat

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

the class InstrumentationImpl method startTracer.

// Preconditions are met: start a new tracer on this thread. There may not be a Transaction on this thread. Code
// in this path MUST NOT attempt to touch the Transaction or do anything that might bring one into existence. This
// inconvenience is absolutely critical to the performance of our async instrumentation.
private Tracer startTracer(TransactionActivity txa, Object target, int signatureId, String metricName, int flags) {
    ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
    MetricNameFormat mnf = MetricNameFormats.getFormatter(target, sig, metricName, flags);
    Tracer tracer;
    if (TracerFlags.isRoot(flags)) {
        // Dispatcher || Async
        tracer = new OtherRootTracer(txa, sig, target, mnf, flags, System.nanoTime());
    } else {
        tracer = new DefaultTracer(txa, sig, target, mnf, flags);
    }
    txa.tracerStarted(tracer);
    return tracer;
}
Also used : 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) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 4 with MetricNameFormat

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

the class TransactionTraceTest method excludeRootTraceFromTT.

/**
 * This test exercises an edge case in our public tracer api by setting excludeFromTransactionTrace = true on a root
 * tracer.
 *
 * The behavior is undefined, but in practice only the root tracer's segment is preserved in the TT. Scala
 * instrumentation is relying on this behavior by only showing the root scala future but not the consecutive calls.
 */
@Test
public void excludeRootTraceFromTT() throws Exception {
    setUp(true, true, false);
    Transaction tx = Transaction.getTransaction(true);
    TransactionActivity txa = TransactionActivity.get();
    // make sure the test env is sane
    Assert.assertNotNull(tx);
    Assert.assertNotNull(txa);
    Assert.assertEquals(tx, txa.getTransaction());
    final ClassMethodSignature sig = new ClassMethodSignature("Test", "dude", "()V");
    final MetricNameFormat metricNameFormat = new SimpleMetricNameFormat("Test.dude", "Test.dude");
    // @Trace( excludeFromTransactionTrace = true )
    final int excludeFromTTFlags = TracerFlags.GENERATE_SCOPED_METRIC;
    // @Trace
    final int defaultFlags = TracerFlags.GENERATE_SCOPED_METRIC | TracerFlags.TRANSACTION_TRACER_SEGMENT;
    DefaultTracer root = new OtherRootTracer(txa, sig, new Object(), metricNameFormat, excludeFromTTFlags, System.currentTimeMillis());
    txa.addTracer(root);
    Assert.assertEquals(txa, root.getTransactionActivity());
    Assert.assertEquals(tx, root.getTransaction());
    final int numChildren = 10;
    for (int i = 0; i < numChildren; ++i) {
        DefaultTracer child = new DefaultTracer(txa, sig, new Object(), metricNameFormat, excludeFromTTFlags, System.currentTimeMillis());
        txa.addTracer(child);
        child.finish(0, null);
        // child honor the flags and do not make a tt segment
        Assert.assertFalse(child.isTransactionSegment());
    }
    root.finish(0, null);
    Assert.assertEquals("Java/java.lang.Object/dude", TransactionSegment.getMetricName(root));
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JSONObject(org.json.simple.JSONObject) TransactionActivity(com.newrelic.agent.TransactionActivity) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 5 with MetricNameFormat

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

the class ExternalRequestImplTest method getTracer.

private DefaultTracer getTracer(String metricName, String transactionSegName) {
    MetricNameFormat format = new SimpleMetricNameFormat(metricName, transactionSegName);
    DefaultTracer tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("class", "method", "()V"), new Object(), format);
    return tracer;
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Aggregations

MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)21 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)13 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)12 Tracer (com.newrelic.agent.tracers.Tracer)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Transaction (com.newrelic.agent.Transaction)8 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)8 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)8 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)8 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)7 Test (org.junit.Test)7 ExitTracer (com.newrelic.agent.bridge.ExitTracer)6 AgentBridge (com.newrelic.agent.bridge.AgentBridge)4 NoOpTransaction (com.newrelic.agent.bridge.NoOpTransaction)4 TransactionActivity (com.newrelic.agent.TransactionActivity)3 ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)3 DefaultMetricNameFormat (com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat)3 SkipTracer (com.newrelic.agent.tracers.SkipTracer)2 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)2 JSONObject (org.json.simple.JSONObject)2