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