Search in sources :

Example 1 with QueryConverter

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"));
}
Also used : BsonDocument(org.bson.BsonDocument) QueryConverter(com.newrelic.api.agent.QueryConverter) ExternalParameters(com.newrelic.api.agent.ExternalParameters) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BsonBoolean(org.bson.BsonBoolean) Trace(com.newrelic.api.agent.Trace)

Example 2 with QueryConverter

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();
    }
}
Also used : BsonDocument(org.bson.BsonDocument) QueryConverter(com.newrelic.api.agent.QueryConverter) BsonBoolean(org.bson.BsonBoolean) Trace(com.newrelic.api.agent.Trace)

Aggregations

QueryConverter (com.newrelic.api.agent.QueryConverter)2 Trace (com.newrelic.api.agent.Trace)2 BsonBoolean (org.bson.BsonBoolean)2 BsonDocument (org.bson.BsonDocument)2 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1 ExternalParameters (com.newrelic.api.agent.ExternalParameters)1