Search in sources :

Example 1 with DatastoreParameters

use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.

the class NewRelicCommandListener method commandStarted.

@Override
public void commandStarted(CommandStartedEvent event) {
    try {
        Segment tracer = NewRelic.getAgent().getTransaction().startSegment(null);
        if (tracer != null) {
            holder.set(tracer);
            String collectionName = getCollectionName(event);
            String operationName = event.getCommandName().intern();
            ServerAddress address = event.getConnectionDescription().getServerAddress();
            DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collectionName).operation(operationName).instance(address.getHost(), address.getPort()).databaseName(event.getDatabaseName()).build();
            tracer.reportAsExternal(params);
        }
    } catch (Throwable t) {
        AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
    }
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) ServerAddress(com.mongodb.ServerAddress) BsonString(org.bson.BsonString) Segment(com.newrelic.api.agent.Segment)

Example 2 with DatastoreParameters

use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.

the class DB_Weave method command.

/*
     * Command calls db.$cmd.find({command}). Since that isn't actually a find operation we want to include its metrics
     * in this tracer. Hence, this tracer is a leaf.
     */
@Trace(leaf = true)
public CommandResult command(final DBObject command, final ReadPreference readPreference, final DBEncoder encoder) {
    String commandName = null;
    String collectionName = null;
    try {
        commandName = command.keySet().iterator().next();
        collectionName = String.valueOf(command.get(commandName));
    } catch (NoSuchElementException nse) {
        NewRelic.getAgent().getLogger().log(Level.FINER, "WARNING: Could not determine mongo command name.");
        commandName = MongoUtil.DEFAULT_OPERATION;
        collectionName = MongoUtil.DEFAULT_COLLECTION;
    }
    CommandResult result = Weaver.callOriginal();
    TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
    DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collectionName).operation(commandName).instance(getMongo().getAddress().getHost(), getMongo().getAddress().getPort()).databaseName(getName()).build();
    tracedMethod.reportAsExternal(params);
    return result;
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) TracedMethod(com.newrelic.api.agent.TracedMethod) NoSuchElementException(java.util.NoSuchElementException) Trace(com.newrelic.api.agent.Trace)

Example 3 with DatastoreParameters

use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.

the class AbstractRedisReactiveCommands_Instrumentation method createDissolvingFlux.

public <T, R> Flux<R> createDissolvingFlux(Supplier<RedisCommand<K, V, T>> commandSupplier) {
    Flux<R> result = Weaver.callOriginal();
    RedisCommand<K, V, T> cmd = commandSupplier.get();
    if (cmd != null) {
        ProtocolKeyword type = cmd.getType();
        String name = type.name();
        String collName = null;
        RedisURI uri = null;
        if (StatefulRedisConnectionImpl_Instrumentation.class.isInstance(connection)) {
            StatefulRedisConnectionImpl_Instrumentation<K, V> connImpl = (StatefulRedisConnectionImpl_Instrumentation<K, V>) connection;
            if (connImpl.redisURI != null) {
                uri = connImpl.redisURI;
            }
        }
        String operation = "UnknownOp";
        ProtocolKeyword t = cmd.getType();
        if ((t != null) && (t.name() != null) && (!t.name().isEmpty())) {
            operation = t.name();
        }
        DatastoreParameters params = null;
        if (uri != null) {
            params = DatastoreParameters.product("Redis").collection(collName).operation(operation).instance(uri.getHost(), Integer.valueOf(uri.getPort())).noDatabaseName().build();
        } else {
            params = DatastoreParameters.product("Redis").collection(collName).operation("").noInstance().noDatabaseName().noSlowQuery().build();
        }
        NRHolder holder = new NRHolder(name, params);
        NRSubscribeConsumer subscriberConsumer = new NRSubscribeConsumer(holder);
        NRErrorConsumer errorConsumer = new NRErrorConsumer(holder);
        Consumer<SignalType> onFinally = new NRSignalTypeConsumer(holder);
        return result.doOnSubscribe(subscriberConsumer).doOnError(errorConsumer).doFinally(onFinally);
    }
    return result;
}
Also used : SignalType(reactor.core.publisher.SignalType) DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) NRErrorConsumer(com.nr.lettuce6.instrumentation.NRErrorConsumer) NRSubscribeConsumer(com.nr.lettuce6.instrumentation.NRSubscribeConsumer) NRHolder(com.nr.lettuce6.instrumentation.NRHolder) NRSignalTypeConsumer(com.nr.lettuce6.instrumentation.NRSignalTypeConsumer) ProtocolKeyword(io.lettuce.core.protocol.ProtocolKeyword)

Example 4 with DatastoreParameters

use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.

the class AbstractRedisReactiveCommands_Instrumentation method createMono.

public <T> Mono<T> createMono(Supplier<RedisCommand<K, V, T>> commandSupplier) {
    Mono<T> result = Weaver.callOriginal();
    RedisCommand<K, V, T> cmd = commandSupplier.get();
    if (cmd != null) {
        ProtocolKeyword type = cmd.getType();
        String name = type.name();
        String collName = null;
        RedisURI uri = null;
        if (StatefulRedisConnectionImpl_Instrumentation.class.isInstance(connection)) {
            StatefulRedisConnectionImpl_Instrumentation<K, V> connImpl = (StatefulRedisConnectionImpl_Instrumentation<K, V>) connection;
            if (connImpl.redisURI != null) {
                uri = connImpl.redisURI;
            }
        }
        String operation = "UnknownOp";
        ProtocolKeyword t = cmd.getType();
        if ((t != null) && (t.name() != null) && (!t.name().isEmpty())) {
            operation = t.name();
        }
        DatastoreParameters params = null;
        if (uri != null) {
            params = DatastoreParameters.product("Redis").collection(collName).operation(operation).instance(uri.getHost(), Integer.valueOf(uri.getPort())).noDatabaseName().build();
        } else {
            params = DatastoreParameters.product("Redis").collection(collName).operation(operation).noInstance().noDatabaseName().noSlowQuery().build();
        }
        NRHolder holder = new NRHolder(name, params);
        NRSubscribeConsumer subscriberConsumer = new NRSubscribeConsumer(holder);
        NRErrorConsumer errorConsumer = new NRErrorConsumer(holder);
        Consumer<SignalType> onFinally = new NRSignalTypeConsumer(holder);
        return result.doOnSubscribe(subscriberConsumer).doOnError(errorConsumer).doFinally(onFinally);
    }
    return result;
}
Also used : SignalType(reactor.core.publisher.SignalType) DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) NRErrorConsumer(com.nr.lettuce6.instrumentation.NRErrorConsumer) NRSubscribeConsumer(com.nr.lettuce6.instrumentation.NRSubscribeConsumer) NRHolder(com.nr.lettuce6.instrumentation.NRHolder) NRSignalTypeConsumer(com.nr.lettuce6.instrumentation.NRSignalTypeConsumer) ProtocolKeyword(io.lettuce.core.protocol.ProtocolKeyword)

Example 5 with DatastoreParameters

use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.

the class DBPort_Weave method instrument.

private void instrument(TracedMethod method, String operation, String collection, String serverUsed, int serverPortUsed, String databaseName) {
    DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collection).operation(operation).instance(serverUsed, serverPortUsed).databaseName(databaseName).build();
    method.reportAsExternal(params);
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters)

Aggregations

DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)31 Trace (com.newrelic.api.agent.Trace)10 SlowQueryDatastoreParameters (com.newrelic.api.agent.SlowQueryDatastoreParameters)9 Test (org.junit.Test)9 AgentConfig (com.newrelic.agent.config.AgentConfig)8 TokenNullCheckClassVisitor (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor)8 ExternalParameters (com.newrelic.api.agent.ExternalParameters)8 SlowQueryWithInputDatastoreParameters (com.newrelic.api.agent.SlowQueryWithInputDatastoreParameters)8 HashMap (java.util.HashMap)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 ClassVisitor (org.objectweb.asm.ClassVisitor)8 ClassNode (org.objectweb.asm.tree.ClassNode)8 CheckClassAdapter (org.objectweb.asm.util.CheckClassAdapter)8 Segment (com.newrelic.api.agent.Segment)3 NRCallbackWrapper (com.nr.agent.mongo.NRCallbackWrapper)3 ProtocolKeyword (io.lettuce.core.protocol.ProtocolKeyword)3 NRErrorConsumer (com.nr.lettuce6.instrumentation.NRErrorConsumer)2 NRHolder (com.nr.lettuce6.instrumentation.NRHolder)2 NRSignalTypeConsumer (com.nr.lettuce6.instrumentation.NRSignalTypeConsumer)2 NRSubscribeConsumer (com.nr.lettuce6.instrumentation.NRSubscribeConsumer)2