Search in sources :

Example 1 with OtherRootSqlTracer

use of com.newrelic.agent.tracers.OtherRootSqlTracer 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 OtherRootSqlTracer

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

the class SqlTraceServiceTest method startSqlTracer.

private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {

        @Override
        public long getDuration() {
            return duration;
        }

        @Override
        public Object getSql() {
            return sql;
        }
    };
    sqlTracer.setConnectionFactory(new ConnectionFactory() {

        @Override
        public Connection getConnection() throws SQLException {
            return null;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return UnknownDatabaseVendor.INSTANCE;
        }
    });
    sqlTracer.setRawSql(sql);
    tx.getTransactionActivity().tracerStarted(sqlTracer);
    return sqlTracer;
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) UnknownDatabaseVendor(com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 3 with OtherRootSqlTracer

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

the class RequestUriConfigTests method startSqlTracer.

private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {

        @Override
        public long getDuration() {
            return duration;
        }

        @Override
        public Object getSql() {
            return sql;
        }
    };
    sqlTracer.setConnectionFactory(new ConnectionFactory() {

        @Override
        public Connection getConnection() {
            return null;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return UnknownDatabaseVendor.INSTANCE;
        }
    });
    sqlTracer.setRawSql(sql);
    tx.getTransactionActivity().tracerStarted(sqlTracer);
    return sqlTracer;
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) UnknownDatabaseVendor(com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 4 with OtherRootSqlTracer

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

the class TransactionStateImpl method getSqlTracer.

@Override
public Tracer getSqlTracer(Transaction tx, Object invocationTarget, ClassMethodSignature sig, String metricName, int flags) {
    TransactionActivity activity = tx.getTransactionActivity();
    if (tx.isIgnore() || activity.isTracerStartLocked()) {
        return null;
    }
    if (currentlyExceedingSegmentLimit(tx, sig)) {
        return UltraLightTracer.createClampedSegment(activity, sig);
    }
    Tracer tracer;
    final MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
    if (TracerFlags.isDispatcher(flags)) {
        tracer = new OtherRootSqlTracer(tx, sig, invocationTarget, mnf);
    } else {
        tracer = new DefaultSqlTracer(tx, sig, invocationTarget, mnf, flags);
    }
    return tracerStarted(tx, sig, tracer);
}
Also used : 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) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer)

Example 5 with OtherRootSqlTracer

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

the class InstrumentationImpl method startSqlTracer.

private Tracer startSqlTracer(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 OtherRootSqlTracer(txa, sig, target, mnf, flags, System.nanoTime());
    } else {
        tracer = new DefaultSqlTracer(txa, sig, target, mnf, flags);
    }
    txa.tracerStarted(tracer);
    return tracer;
}
Also used : 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) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer)

Aggregations

OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)6 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)5 Transaction (com.newrelic.agent.Transaction)4 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)4 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)4 Tracer (com.newrelic.agent.tracers.Tracer)4 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)4 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)4 ExitTracer (com.newrelic.agent.bridge.ExitTracer)3 AgentBridge (com.newrelic.agent.bridge.AgentBridge)2 NoOpTransaction (com.newrelic.agent.bridge.NoOpTransaction)2 ConnectionFactory (com.newrelic.agent.bridge.datastore.ConnectionFactory)2 DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)2 UnknownDatabaseVendor (com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor)2 SqlTracer (com.newrelic.agent.tracers.SqlTracer)2 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)2 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 DummyConnection (sql.DummyConnection)2