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