use of com.newrelic.api.agent.QueryConverter in project newrelic-java-agent by newrelic.
the class ApiTest method runTestDatastoreSlowQueryAPI.
@Trace(dispatcher = true)
private void runTestDatastoreSlowQueryAPI() {
String vendor = "MongoDB";
String collection = "Users";
String operation = "SELECT";
String host = "awesome-host";
Integer port = 27017;
BsonDocument rawQuery = new BsonDocument("key", new BsonBoolean(true));
QueryConverter<BsonDocument> MONGO_QUERY_CONVERTER = new QueryConverter<BsonDocument>() {
@Override
public String toRawQueryString(BsonDocument query) {
return query.toString();
}
@Override
public String toObfuscatedQueryString(BsonDocument query) {
return query.toString();
}
};
ExternalParameters params = DatastoreParameters.product(vendor).collection(collection).operation(operation).instance(host, port).noDatabaseName().slowQuery(rawQuery, MONGO_QUERY_CONVERTER).build();
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
Tracer rootTracer = Transaction.getTransaction(false).getRootTracer();
rootTracer.finish(0, null);
Map<String, Object> attributes = rootTracer.getAgentAttributes();
Assert.assertNotNull(attributes.get("sql"));
Assert.assertNotNull(attributes.get("sql_obfuscated"));
}
use of com.newrelic.api.agent.QueryConverter in project newrelic-java-agent by newrelic.
the class CircuitBreakerApiTest method runTestDatastoreSlowQueryAPI.
@Trace(dispatcher = true)
private void runTestDatastoreSlowQueryAPI() {
String vendor = "MongoDB";
String collection = "Users";
String operation = "SELECT";
String host = "awesome-host";
Integer port = 27017;
// the raw query object
BsonDocument rawQuery = new BsonDocument("key", new BsonBoolean(true));
QueryConverter<BsonDocument> MONGO_QUERY_CONVERTER = new QueryConverter<BsonDocument>() {
@Override
public String toRawQueryString(BsonDocument query) {
return query.toString();
}
@Override
public String toObfuscatedQueryString(BsonDocument query) {
return query.toString();
}
};
NewRelic.getAgent().getTracedMethod().reportAsExternal(DatastoreParameters.product(vendor).collection(collection).operation(operation).instance(host, port).noDatabaseName().slowQuery(rawQuery, MONGO_QUERY_CONVERTER).build());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations