Search in sources :

Example 1 with DatastoreVendor

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

the class DefaultTracerTest method testExternalParameters.

@Test
public void testExternalParameters() throws URISyntaxException {
    TransactionActivity.clear();
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    TransactionActivity txa = TransactionActivity.get();
    Tracer root = new OtherRootTracer(tx, new ClassMethodSignature("com.newrelic.agent.TracedActivityTest", "makeTransaction", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
    txa.tracerStarted(root);
    final TransactionStats stats = root.getTransactionActivity().getTransactionStats();
    // http external
    final String library = "unittest";
    final URI uri = new URI("http://localhost");
    final String host = uri.getHost();
    final String procedure = "connect";
    int externalCount = 0;
    {
        // generic external
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        assertExternal(stats, externalCount, host, library, procedure);
        // multiple calls to addExternalParameters should only apply the last call
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        // metrics should only be recorded when the tracer finishes
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(externalCount, stats.getScopedStats().getOrCreateResponseTimeStats("External/" + host + "/" + library + "/" + procedure).getCallCount());
        tracer.finish(0, null);
        externalCount++;
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(externalCount, stats.getScopedStats().getOrCreateResponseTimeStats("External/" + host + "/" + library + "/" + procedure).getCallCount());
    }
    final DatastoreVendor vendor = DatastoreVendor.MySQL;
    final String collection = "stores";
    final String operation = "select";
    final int port = 666;
    int datastoreCount = 0;
    {
        // datastore
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(DatastoreParameters.product(vendor.toString()).collection(collection).operation(operation).instance(host, port).build());
        assertDatastore(stats, datastoreCount, vendor.toString(), collection, operation, host, port);
        tracer.finish(0, null);
        datastoreCount++;
        assertDatastore(stats, datastoreCount, vendor.toString(), collection, operation, host, port);
        // http external should be unchanged
        assertExternal(stats, externalCount, host, library, procedure);
    }
    {
        // http + DT
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.addOutboundRequestHeaders(new Outbound());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(HttpParameters.library(library).uri(uri).procedure(procedure).inboundHeaders(new Inbound("Foo")).build());
        assertCat(tracer, false);
        assertExternal(stats, externalCount, host, library, procedure);
        tracer.finish(0, null);
        externalCount++;
        // DT is enabled, there should not be any CAT
        assertCat(tracer, false);
        // ExternalTransaction/localhost/12345/Foo
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Foo").getCallCount());
    }
    {
        // last inboundHeaders win
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.addOutboundRequestHeaders(new Outbound());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(HttpParameters.library(library).uri(uri).procedure(procedure).inboundHeaders(new Inbound("Foo")).build());
        // headers trump the previous call
        tracer.readInboundResponseHeaders(new Inbound("Bar"));
        assertCat(tracer, false);
        assertExternal(stats, externalCount, host, library, procedure);
        tracer.finish(0, null);
        externalCount++;
        // DT is enabled, there should not be any CAT
        assertCat(tracer, false);
        // ExternalTransaction/localhost/12345/Foo
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Bar").getCallCount());
    }
    {
        // set headers manually
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.addOutboundRequestHeaders(new Outbound());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        // headers trump the previous call
        tracer.readInboundResponseHeaders(new Inbound("Baz"));
        assertCat(tracer, false);
        assertExternal(stats, externalCount, host, library, procedure);
        tracer.finish(0, null);
        externalCount++;
        // DT is enabled, there should not be any CAT
        assertCat(tracer, false);
        // ExternalTransaction/localhost/12345/Foo
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Baz").getCallCount());
    }
    root.finish(0, null);
}
Also used : TransactionActivity(com.newrelic.agent.TransactionActivity) URI(java.net.URI) DatastoreVendor(com.newrelic.agent.bridge.datastore.DatastoreVendor) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) Test(org.junit.Test)

Example 2 with DatastoreVendor

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

the class DefaultExplainPlanExecutorTest method testMultipleStatementNoExplainPlan.

@Test
public void testMultipleStatementNoExplainPlan() throws SQLException {
    SqlTracerExplainInfo tracer = createSqlTracerInfo("SELECT * FROM users; SELECT * FROM users");
    DefaultExplainPlanExecutor explainPlanExecutor = new DefaultExplainPlanExecutor(tracer, (String) tracer.getSql(), RecordSql.raw);
    explainPlanExecutor.runExplainPlan(null, null, new DatabaseVendor() {

        @Override
        public String getName() {
            return "MyDBVendor";
        }

        @Override
        public String getType() {
            return "MyDB";
        }

        @Override
        public boolean isExplainPlanSupported() {
            return true;
        }

        @Override
        public String getExplainPlanSql(String sql) throws SQLException {
            return sql;
        }

        @Override
        public Collection<Collection<Object>> parseExplainPlanResultSet(int columnCount, ResultSet rs, RecordSql recordSql) throws SQLException {
            return null;
        }

        @Override
        public String getExplainPlanFormat() {
            return null;
        }

        @Override
        public DatastoreVendor getDatastoreVendor() {
            return DatastoreVendor.JDBC;
        }
    });
    assertFalse(tracer.hasExplainPlan());
}
Also used : SqlTracerExplainInfo(com.newrelic.agent.tracers.SqlTracerExplainInfo) DatastoreVendor(com.newrelic.agent.bridge.datastore.DatastoreVendor) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) SQLException(java.sql.SQLException) RecordSql(com.newrelic.agent.bridge.datastore.RecordSql) ResultSet(java.sql.ResultSet) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

DatastoreVendor (com.newrelic.agent.bridge.datastore.DatastoreVendor)2 Test (org.junit.Test)2 Transaction (com.newrelic.agent.Transaction)1 TransactionActivity (com.newrelic.agent.TransactionActivity)1 DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)1 RecordSql (com.newrelic.agent.bridge.datastore.RecordSql)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 SqlTracerExplainInfo (com.newrelic.agent.tracers.SqlTracerExplainInfo)1 URI (java.net.URI)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1