Search in sources :

Example 11 with DatastoreParameters

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();
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) Trace(com.newrelic.api.agent.Trace)

Example 12 with DatastoreParameters

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;
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) NRCallbackWrapper(com.nr.agent.mongo.NRCallbackWrapper)

Example 13 with DatastoreParameters

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;
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) Trace(com.newrelic.api.agent.Trace)

Example 14 with DatastoreParameters

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));
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) SlowQueryDatastoreParameters(com.newrelic.api.agent.SlowQueryDatastoreParameters) SlowQueryWithInputDatastoreParameters(com.newrelic.api.agent.SlowQueryWithInputDatastoreParameters) ClassVisitor(org.objectweb.asm.ClassVisitor) TokenNullCheckClassVisitor(com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor) SlowQueryDatastoreParameters(com.newrelic.api.agent.SlowQueryDatastoreParameters) SlowQueryWithInputDatastoreParameters(com.newrelic.api.agent.SlowQueryWithInputDatastoreParameters) AgentConfig(com.newrelic.agent.config.AgentConfig) ExternalParameters(com.newrelic.api.agent.ExternalParameters) CheckClassAdapter(org.objectweb.asm.util.CheckClassAdapter) Test(org.junit.Test)

Example 15 with DatastoreParameters

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);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) SlowQueryDatastoreParameters(com.newrelic.api.agent.SlowQueryDatastoreParameters) SlowQueryWithInputDatastoreParameters(com.newrelic.api.agent.SlowQueryWithInputDatastoreParameters) ClassVisitor(org.objectweb.asm.ClassVisitor) TokenNullCheckClassVisitor(com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor) SlowQueryDatastoreParameters(com.newrelic.api.agent.SlowQueryDatastoreParameters) SlowQueryWithInputDatastoreParameters(com.newrelic.api.agent.SlowQueryWithInputDatastoreParameters) AgentConfig(com.newrelic.agent.config.AgentConfig) ExternalParameters(com.newrelic.api.agent.ExternalParameters) CheckClassAdapter(org.objectweb.asm.util.CheckClassAdapter) Test(org.junit.Test)

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