use of com.newrelic.agent.config.ClassTransformerConfig in project newrelic-java-agent by newrelic.
the class ExtensionService method initializeBuiltInExtensions.
private void initializeBuiltInExtensions() {
ClassTransformerConfig classTransformerConfig = config.getDefaultAgentConfig().getClassTransformerConfig();
String jarFileName = AgentJarHelper.getAgentJarFileName();
if (jarFileName == null) {
getLogger().log(Level.SEVERE, "Unable to find the agent jar file");
return;
}
boolean defaultInstrumentationDisabled = !classTransformerConfig.isDefaultInstrumentationEnabled();
boolean builtinExtensionsDisabled = !classTransformerConfig.isBuiltinExtensionEnabled();
boolean builtinExtensionsExplicitlyEnabled = classTransformerConfig.isBuiltinExtensionEnabled();
if (defaultInstrumentationDisabled && !builtinExtensionsExplicitlyEnabled) {
getLogger().log(Level.FINEST, "Instrumentation is disabled by default. Not loading builtin extensions");
} else if (builtinExtensionsDisabled) {
getLogger().log(Level.INFO, "Builtin extensions are disabled");
} else {
try {
JarExtension jarExtension = JarExtension.create(getLogger(), extensionParsers, jarFileName);
addJarExtensions(jarExtension);
} catch (IOException e) {
getLogger().severe(MessageFormat.format("Unable to read extensions from the agent jar : {0}", e.toString()));
getLogger().log(Level.FINER, "Extensions error", e);
}
}
}
use of com.newrelic.agent.config.ClassTransformerConfig in project newrelic-java-agent by newrelic.
the class ClassLoaderClassTransformer method buildCheckAccessPatcherPackage.
private WeavePackage buildCheckAccessPatcherPackage() {
WeavePackageConfig checkAccessPatcher = WeavePackageConfig.builder().name("check-access-patcher").errorHandleClassNode(LogAndReturnOriginal.ERROR_HANDLER_NODE).extensionClassTemplate(extensionTemplate).build();
List<byte[]> checkAccessPackageBytes = new ArrayList<>();
try {
// us to selectively get around security manager checks from instrumentation modules (if config is enabled)
if (System.getSecurityManager() != null) {
ClassTransformerConfig config = ServiceFactory.getConfigService().getDefaultAgentConfig().getClassTransformerConfig();
if (config.isGrantPackageAccess()) {
// 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[] classloaderPackageAccessInstrumentationBytes = WeaveUtils.getClassBytesFromClassLoaderResource(ClassLoaderPackageAccessInstrumentation.class.getName(), ClassLoaderClassTransformer.class.getClassLoader());
checkAccessPackageBytes.add(classloaderPackageAccessInstrumentationBytes);
return new WeavePackage(checkAccessPatcher, checkAccessPackageBytes);
}
}
} catch (IOException e) {
Agent.LOG.log(Level.FINE, e, "Unable to initialize agent classloader instrumentation");
}
return null;
}
use of com.newrelic.agent.config.ClassTransformerConfig in project newrelic-java-agent by newrelic.
the class ClassWeaverService method loadExternalWeavePackages.
/**
* Load new instrumentation packages from disk and put any new matchers in the matchers collection.
*
* @param weaveExtensions
*/
private Collection<ClassMatchVisitorFactory> loadExternalWeavePackages(Collection<File> weaveExtensions) {
Collection<ClassMatchVisitorFactory> matchers = new HashSet<>();
for (File weaveExtension : weaveExtensions) {
try (JarInputStream stream = new JarInputStream(new FileInputStream(weaveExtension))) {
AgentConfig agentConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
WeavePackageConfig weaveConfig = createWeavePackageConfig(stream, weaveExtension.getAbsolutePath(), instrumentation, WeavePackageType.CUSTOM, agentConfig);
ClassTransformerConfig classTransformerConfig = agentConfig.getClassTransformerConfig();
String instrName = weaveConfig.getName();
if (weavePackageManager.isRegistered(instrName)) {
weavePackageManager.deregister(instrName);
this.externalWeavePackages.remove(weaveExtension.getAbsolutePath());
}
if (!classTransformerConfig.isWeavePackageEnabled(weaveConfig)) {
if (weaveConfig.isEnabled()) {
// Only log this if the module has been explicitly disabled (not if it is disabled by default)
LOG.log(Level.INFO, "Instrumentation {0} is disabled. Skipping.", instrName);
}
continue;
}
WeavePackage externalPackage = WeavePackage.createWeavePackage(stream, weaveConfig);
if (externalPackage.getPackageViolations().size() > 0) {
LOG.log(Level.FINER, "skip loading external weave package: {0}", instrName);
for (WeaveViolation violation : externalPackage.getPackageViolations()) {
LOG.log(Level.FINER, "\t{0}", violation);
}
} else {
weavePackageManager.register(externalPackage);
externalWeavePackages.put(weaveExtension.getAbsolutePath(), weaveConfig.getName());
}
} catch (Exception e) {
LOG.log(Level.FINE, e, "Error reading weave extension {0}", weaveExtension.getAbsolutePath());
}
}
return matchers;
}
use of com.newrelic.agent.config.ClassTransformerConfig in project newrelic-java-agent by newrelic.
the class ClassWeaverService method createWeavePackage.
/**
* Create a weave package from a jar source.
*
* @param inputStream The JarInputStream to read from.
* @param source URL where the jar was read from.
*/
private WeavePackage createWeavePackage(InputStream inputStream, String source) throws Exception {
JarInputStream jarStream = new JarInputStream(inputStream);
AgentConfig agentConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
WeavePackageConfig weavePackageConfig = createWeavePackageConfig(jarStream, source, instrumentation, WeavePackageType.INTERNAL, agentConfig);
ClassTransformerConfig classTransformerConfig = agentConfig.getClassTransformerConfig();
String weavePackageName = weavePackageConfig.getName();
if (!classTransformerConfig.isWeavePackageEnabled(weavePackageConfig)) {
if (weavePackageConfig.isEnabled()) {
// Only log this if the module has been explicitly disabled (not if it is disabled by default)
LOG.log(Level.INFO, "Instrumentation {0} is disabled. Skipping.", weavePackageName);
}
return null;
}
if ("com.newrelic.instrumentation.jcache-1.0.0".equals(weavePackageName)) {
Boolean jcacheDatastoreEnabled = agentConfig.getValue("class_transformer.com.newrelic.instrumentation.jcache-datastore-1.0.0.enabled", Boolean.FALSE);
if (jcacheDatastoreEnabled) {
LOG.log(Level.INFO, " Instrumentation {0} is disabled since {1} is enabled. Skipping.", weavePackageName, "com.newrelic.instrumentation.jcache-datastore-1.0.0");
return null;
}
}
WeavePackage weavePackage = CachedWeavePackage.createWeavePackage(new URL(source), jarStream, weavePackageConfig);
return weavePackage;
}
use of com.newrelic.agent.config.ClassTransformerConfig in project newrelic-java-agent by newrelic.
the class PointCutConfiguration method isEnabled.
public boolean isEnabled() {
boolean groupExplicitlyEnabled = pointCutGroupConfig.getProperty("enabled", false);
boolean classExplicitlyEnabled = pointCutConfig.getProperty("enabled", false);
if (groupExplicitlyEnabled || classExplicitlyEnabled) {
Agent.LOG.info(MessageFormat.format("Enabled point cut \"{1}\" (\"{2}\")", getName(), getGroupName()));
return true;
}
boolean groupExplicitlyDisabled = !pointCutGroupConfig.getProperty("enabled", true);
boolean classExplicitlyDisabled = !pointCutConfig.getProperty("enabled", true);
if (groupExplicitlyDisabled && classExplicitlyEnabled) {
Agent.LOG.info(MessageFormat.format("Disabled point cut \"{1}\" (\"{2}\")", getName(), getGroupName()));
return false;
}
if (groupExplicitlyDisabled || classExplicitlyDisabled) {
Agent.LOG.info(MessageFormat.format("Disabled point cut \"{1}\" (\"{2}\")", getName(), getGroupName()));
return false;
}
ClassTransformerConfig classTransformerConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getClassTransformerConfig();
boolean instrumentationDefaultDisabled = !classTransformerConfig.isDefaultInstrumentationEnabled();
if (instrumentationDefaultDisabled) {
String msg = MessageFormat.format("Instrumentation is disabled by default. Disabled point cut \"{0}\" (\"{1}\")", getName(), getGroupName());
Agent.LOG.info(msg);
return false;
}
return enabledByDefault;
}
Aggregations