Search in sources :

Example 16 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigInstrumentationDisableSystemPropertyOverride.

@Test
public void weavePackageConfigInstrumentationDisableSystemPropertyOverride() {
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    Map<String, Object> configMap = new HashMap<>();
    ClassTransformerConfig config = ClassTransformerConfigImpl.createClassTransformerConfig(configMap, true, false);
    Assert.assertTrue(config.isDefaultInstrumentationEnabled());
    configMap.put("instrumentation_default:enabled", false);
    configMap = buildConfigMap(configMap);
    config = ClassTransformerConfigImpl.createClassTransformerConfig(configMap, true, false);
    Assert.assertFalse(config.isDefaultInstrumentationEnabled());
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).build();
    assertFalse(config.isWeavePackageEnabled(weaveConfig));
    System.setProperty("newrelic.config.class_transformer." + moduleName + ".enabled", "true");
    weaveConfig = WeavePackageConfig.builder().name(moduleName).build();
    assertTrue(config.isWeavePackageEnabled(weaveConfig));
    System.clearProperty("newrelic.config.class_transformer." + moduleName + ".enabled");
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 17 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method weavePackageConfigInstrumentationDisable.

@Test
public void weavePackageConfigInstrumentationDisable() {
    final String moduleName = "com.newrelic.instrumentation.mymodule-1.0";
    HashMap<String, Object> props = new HashMap<>();
    HashMap<String, Object> instDefault = new HashMap<>();
    ClassTransformerConfig config = new ClassTransformerConfigImpl(props, true);
    WeavePackageConfig weaveConfig = WeavePackageConfig.builder().name(moduleName).enabled(true).build();
    assertTrue(config.isWeavePackageEnabled(weaveConfig));
    instDefault.put("enabled", false);
    props.put(ClassTransformerConfigImpl.DEFAULT_INSTRUMENTATION, instDefault);
    config = ClassTransformerConfigImpl.createClassTransformerConfig(props, true, false);
    assertFalse(config.isWeavePackageEnabled(weaveConfig));
    props.put(moduleName, ImmutableMap.of("enabled", true));
    assertTrue(config.isWeavePackageEnabled(weaveConfig));
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 18 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class RegisterInstrumentationCloseableTest method init.

@BeforeClass
public static void init() throws IOException {
    List<byte[]> weaveBytes = new ArrayList<>();
    WeavePackageConfig config = WeavePackageConfig.builder().name("agent_unittest").source("newrelic_agent.unit_test").build();
    testPackage = new WeavePackage(config, weaveBytes);
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) ArrayList(java.util.ArrayList) WeavePackage(com.newrelic.weave.weavepackage.WeavePackage) BeforeClass(org.junit.BeforeClass)

Example 19 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class EnumAccessTest method makeWeavePackage.

public static WeavePackage makeWeavePackage() throws IOException {
    List<byte[]> weaveBytes = new ArrayList<>();
    weaveBytes.add(WeaveTestUtils.getClassBytes("com.newrelic.weave.EnumAccessTest$State_Instrumentation"));
    weaveBytes.add(WeaveTestUtils.getClassBytes("com.newrelic.weave.EnumAccessTest$Foo_Instrumentation"));
    WeavePackageConfig config = WeavePackageConfig.builder().name("weave_unittest").source("com.newrelic.weave.weavepackage.testclasses").build();
    return new WeavePackage(config, weaveBytes);
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) ArrayList(java.util.ArrayList) WeavePackage(com.newrelic.weave.weavepackage.WeavePackage)

Example 20 with WeavePackageConfig

use of com.newrelic.weave.weavepackage.WeavePackageConfig in project newrelic-java-agent by newrelic.

the class ClassLoaderClassTransformer method buildBaseClassLoaderPatcherPackage.

private WeavePackage buildBaseClassLoaderPatcherPackage() {
    WeavePackageConfig baseClassloaderPatcher = WeavePackageConfig.builder().name("base-agent-classloader-patcher").errorHandleClassNode(LogAndReturnOriginal.ERROR_HANDLER_NODE).extensionClassTemplate(extensionTemplate).build();
    List<byte[]> baseWeavePackageBytes = new ArrayList<>();
    try {
        // Grab the bytes of our Agent Classloader instrumentation class. Note: This call uses "findResource" but
        // this is ok because we are not under a classloader lock at this point, we are still in the premain()
        byte[] baseClassloaderPatcherInstrumentationBytes = WeaveUtils.getClassBytesFromClassLoaderResource(AgentClassLoaderBaseInstrumentation.class.getName(), ClassLoaderClassTransformer.class.getClassLoader());
        baseWeavePackageBytes.add(baseClassloaderPatcherInstrumentationBytes);
    } catch (IOException e) {
        Agent.LOG.log(Level.FINE, e, "Unable to initialize agent classloader instrumentation");
    }
    return new WeavePackage(baseClassloaderPatcher, baseWeavePackageBytes);
}
Also used : WeavePackageConfig(com.newrelic.weave.weavepackage.WeavePackageConfig) AgentClassLoaderBaseInstrumentation(com.newrelic.agent.instrumentation.builtin.AgentClassLoaderBaseInstrumentation) ArrayList(java.util.ArrayList) WeavePackage(com.newrelic.weave.weavepackage.WeavePackage) IOException(java.io.IOException)

Aggregations

WeavePackageConfig (com.newrelic.weave.weavepackage.WeavePackageConfig)22 Test (org.junit.Test)10 WeavePackage (com.newrelic.weave.weavepackage.WeavePackage)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)4 ClassTransformerConfig (com.newrelic.agent.config.ClassTransformerConfig)3 URL (java.net.URL)3 JarInputStream (java.util.jar.JarInputStream)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 WeaveViolation (com.newrelic.weave.violation.WeaveViolation)2 CachedWeavePackage (com.newrelic.weave.weavepackage.CachedWeavePackage)2 File (java.io.File)2 HashSet (java.util.HashSet)2 AgentClassLoaderBaseInstrumentation (com.newrelic.agent.instrumentation.builtin.AgentClassLoaderBaseInstrumentation)1 AgentClassLoaderInstrumentation (com.newrelic.agent.instrumentation.builtin.AgentClassLoaderInstrumentation)1 ClassLoaderPackageAccessInstrumentation (com.newrelic.agent.instrumentation.builtin.ClassLoaderPackageAccessInstrumentation)1 ClassMatchVisitorFactory (com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory)1 AgentPostprocessors (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPostprocessors)1 AgentPreprocessors (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors)1