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