Search in sources :

Example 16 with ExternalParameters

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

the class SnsClient_Instrumentation method publish.

@Trace
public PublishResponse publish(PublishRequest publishRequest) throws InvalidParameterException, InvalidParameterValueException, InternalErrorException, NotFoundException, EndpointDisabledException, PlatformApplicationDisabledException, AuthorizationErrorException, KmsDisabledException, KmsInvalidStateException, KmsNotFoundException, KmsOptInRequiredException, KmsThrottlingException, KmsAccessDeniedException, InvalidSecurityException, AwsServiceException, SdkClientException, SnsException {
    TracedMethod tracedMethod = AgentBridge.getAgent().getTracedMethod();
    ExternalParameters params = SnsClientInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    tracedMethod.reportAsExternal(params);
    return Weaver.callOriginal();
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Example 17 with ExternalParameters

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

the class AgentPreprocessorsTest method testRewriteSlowQueryNoHighSecurity.

@Test
public void testRewriteSlowQueryNoHighSecurity() throws Exception {
    final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass1";
    Map<String, Object> confProps = new HashMap<>();
    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);
    ExternalParametersFactoryTestClass1 testClass = (ExternalParametersFactoryTestClass1) 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)

Example 18 with ExternalParameters

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

the class AgentPreprocessorsTest method testRewriteSlowQueryBuilderWithHighSecurity.

@Test
public void testRewriteSlowQueryBuilderWithHighSecurity() throws Exception {
    final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass6";
    Map<String, Object> confProps = new HashMap<>();
    confProps.put("high_security", true);
    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);
    ExternalParametersFactoryTestClass6 testClass = (ExternalParametersFactoryTestClass6) 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 19 with ExternalParameters

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

the class AgentPreprocessorsTest method testRewriteSlowQueryWithHighSecurity.

@Test
public void testRewriteSlowQueryWithHighSecurity() throws Exception {
    final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass2";
    Map<String, Object> confProps = new HashMap<>();
    confProps.put("high_security", true);
    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);
    ExternalParametersFactoryTestClass2 testClass = (ExternalParametersFactoryTestClass2) 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 20 with ExternalParameters

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

the class AgentPreprocessorsTest method testRewriteSlowQueryBuilderWithHighSecurityAndNonPresentListToCollect.

@Test
public void testRewriteSlowQueryBuilderWithHighSecurityAndNonPresentListToCollect() throws Exception {
    final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass8";
    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);
    ExternalParametersFactoryTestClass8 testClass = (ExternalParametersFactoryTestClass8) 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)

Aggregations

ExternalParameters (com.newrelic.api.agent.ExternalParameters)23 Test (org.junit.Test)12 AgentConfig (com.newrelic.agent.config.AgentConfig)8 TokenNullCheckClassVisitor (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor)8 DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)8 SlowQueryDatastoreParameters (com.newrelic.api.agent.SlowQueryDatastoreParameters)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 Trace (com.newrelic.api.agent.Trace)7 URISyntaxException (java.net.URISyntaxException)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 Tracer (com.newrelic.agent.tracers.Tracer)3 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)3 Segment (com.newrelic.api.agent.Segment)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2