use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.
the class Connection_Instrumentation method getMore.
@Trace(leaf = true)
public <T> QueryResult<T> getMore(MongoNamespace namespace, long cursorId, int numberToReturn, Decoder<T> resultDecoder) {
DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(namespace.getCollectionName()).operation(MongoUtil.OP_GET_MORE).instance(getDescription().getServerAddress().getHost(), getDescription().getServerAddress().getPort()).databaseName(namespace.getDatabaseName()).build();
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
return Weaver.callOriginal();
}
use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.
the class MongoCollectionImpl_Instrumentation method instrument.
private <T> SingleResultCallback<T> instrument(SingleResultCallback<T> callback, String operationName) {
if (callback instanceof NRCallbackWrapper) {
return callback;
}
NRCallbackWrapper<T> wrapper = new NRCallbackWrapper<T>(callback);
DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(getNamespace().getCollectionName()).operation(operationName).instance(address.getHost(), address.getPort()).databaseName(getNamespace().getDatabaseName()).build();
wrapper.params = params;
wrapper.token = NewRelic.getAgent().getTransaction().getToken();
wrapper.segment = NewRelic.getAgent().getTransaction().startSegment(operationName);
return wrapper;
}
use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.
the class HttpSolrServer_Instrumentation method request.
@Trace
public NamedList<Object> request(final SolrRequest request, ResponseParser processor) {
NamedList<Object> namedList = Weaver.callOriginal();
String collection = url.getPath();
collection = collection.startsWith("/") ? collection.substring(1) : collection;
DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.Solr.name()).collection(collection).operation(request.getMethod().toString()).instance(url.getHost(), url.getPort()).databaseName(null).build();
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
return namedList;
}
use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryWithHighSecurityAndNonPresentListToCollect.
@Test
public void testRewriteSlowQueryWithHighSecurityAndNonPresentListToCollect() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass4";
Map<String, Object> confProps = new HashMap<>();
confProps.put("high_security", true);
Map<String, Object> ttConfig = new HashMap<>();
ttConfig.put("collect_slow_queries_from", "some-other-module");
confProps.put("transaction_tracer", ttConfig);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(confProps);
byte[] bytes = getClassBytesFromClassLoaderResource(classname, classloader);
Assert.assertNotNull(bytes);
ClassNode source = WeaveUtils.convertToClassNode(bytes);
ClassNode result = new ClassNode(WeaveUtils.ASM_API_LEVEL);
ClassVisitor cv = new CheckClassAdapter(result);
AgentPreprocessors preprocessors = new AgentPreprocessors(agentConfig, null);
preprocessors.setInstrumentationTitle(INSTRUMENTATION_TITLE);
cv = preprocessors.rewriteSlowQueryIfRequired(cv);
source.accept(cv);
Class<?> clazz = addToClassloader(result, classloader);
Assert.assertNotNull(clazz);
ExternalParametersFactoryTestClass4 testClass = (ExternalParametersFactoryTestClass4) clazz.newInstance();
assertNotNull(testClass);
ExternalParameters regularDatastore = testClass.createRegularDatastore();
assertNotNull(regularDatastore);
assertTrue(regularDatastore instanceof DatastoreParameters);
ExternalParameters slowQueryDatastore = testClass.createSlowQueryDatastore();
assertNotNull(slowQueryDatastore);
// AgentPreprocessors should re-write the call to return a regular DatastoreParameters object
assertTrue(!(slowQueryDatastore instanceof SlowQueryDatastoreParameters));
ExternalParameters slowQueryWithInputDatastore = testClass.createSlowQueryWithInputDatastore();
assertNotNull(slowQueryWithInputDatastore);
// AgentPreprocessors should re-write the call to return a regular DatastoreParameters object
assertTrue(!(slowQueryWithInputDatastore instanceof SlowQueryWithInputDatastoreParameters));
}
use of com.newrelic.api.agent.DatastoreParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryWithHighSecurityAndListToCollect.
@Test
public void testRewriteSlowQueryWithHighSecurityAndListToCollect() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass3";
Map<String, Object> confProps = new HashMap<>();
confProps.put("high_security", true);
Map<String, Object> ttConfig = new HashMap<>();
ttConfig.put("collect_slow_queries_from", INSTRUMENTATION_TITLE + ",some-other-module");
confProps.put("transaction_tracer", ttConfig);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(confProps);
byte[] bytes = getClassBytesFromClassLoaderResource(classname, classloader);
Assert.assertNotNull(bytes);
ClassNode source = WeaveUtils.convertToClassNode(bytes);
ClassNode result = new ClassNode(WeaveUtils.ASM_API_LEVEL);
ClassVisitor cv = new CheckClassAdapter(result);
AgentPreprocessors preprocessors = new AgentPreprocessors(agentConfig, null);
preprocessors.setInstrumentationTitle(INSTRUMENTATION_TITLE);
cv = preprocessors.rewriteSlowQueryIfRequired(cv);
source.accept(cv);
Class<?> clazz = addToClassloader(result, classloader);
Assert.assertNotNull(clazz);
ExternalParametersFactoryTestClass3 testClass = (ExternalParametersFactoryTestClass3) clazz.newInstance();
assertNotNull(testClass);
ExternalParameters regularDatastore = testClass.createRegularDatastore();
assertNotNull(regularDatastore);
assertTrue(regularDatastore instanceof DatastoreParameters);
ExternalParameters slowQueryDatastore = testClass.createSlowQueryDatastore();
assertNotNull(slowQueryDatastore);
assertTrue(slowQueryDatastore instanceof SlowQueryDatastoreParameters);
ExternalParameters slowQueryWithInputDatastore = testClass.createSlowQueryWithInputDatastore();
assertNotNull(slowQueryWithInputDatastore);
assertTrue(slowQueryWithInputDatastore instanceof SlowQueryWithInputDatastoreParameters);
}
Aggregations