use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class InstrumentTestUtils method createTransformerAndRetransformInterface.
public static void createTransformerAndRetransformInterface(String interfaceName, String methodName, String methodDesc) throws UnmodifiableClassException {
ExtensionClassAndMethodMatcher pc = InstrumentTestUtils.createInterfacePointCut(interfaceName, methodName, methodDesc);
List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
list.add(pc);
ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
InstrumentTestUtils.retransformAllMatching(pc);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method convertToEnabledPointCuts.
/**
* Takes in an xml extension object and converts it to a list of point cuts.
*
* @return The list of point cuts.
*/
private static List<ExtensionClassAndMethodMatcher> convertToEnabledPointCuts(final Extension extension, final String extensionName, Map<String, MethodMapper> classesToMethods, boolean custom, InstrumentationType type, boolean isAttsEnabled) {
List<ExtensionClassAndMethodMatcher> pointCutsOut = new ArrayList<>();
if (extension != null) {
String defaultMetricPrefix = createDefaultMetricPrefix(extension.getInstrumentation(), custom);
List<Pointcut> inCuts = extension.getInstrumentation().getPointcut();
if (inCuts != null && !inCuts.isEmpty()) {
for (Pointcut cut : inCuts) {
try {
ExtensionClassAndMethodMatcher pc = createPointCut(extension, cut, defaultMetricPrefix, extensionName, classesToMethods, custom, type, isAttsEnabled);
if (pc != null) {
logPointCutCreation(pc);
pointCutsOut.add(pc);
}
} catch (Exception e) {
String msg = MessageFormat.format(XmlParsingMessages.GEN_PC_ERROR, extensionName, e.toString());
Agent.LOG.log(Level.SEVERE, msg);
Agent.LOG.log(Level.FINER, msg, e);
}
}
} else {
String msg = MessageFormat.format("There were no point cuts in the extension {0}.", extensionName);
Agent.LOG.log(Level.INFO, msg);
}
}
return pointCutsOut;
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method convertToPointCutsForValidation.
/**
* Should be used to validate the XML. No logging is performed with this method.
*
* @param ext The extension read in.
* @return The list of point cuts.
* @throws XmlException
*/
public static List<ExtensionClassAndMethodMatcher> convertToPointCutsForValidation(Extension ext) throws XmlException {
List<ExtensionClassAndMethodMatcher> pointCutsOut = new ArrayList<>();
Instrumentation inst = ext.getInstrumentation();
validateExtensionAttributes(ext);
// this mandates that an instrumentation element is present
validateInstrument(inst);
List<Pointcut> pcs = inst.getPointcut();
String defaultMetricPrefix = createDefaultMetricPrefix(inst, true);
Map<String, MethodMapper> classesToMethods = new HashMap<>();
for (Pointcut pc : pcs) {
pointCutsOut.add(createPointCut(ext, pc, defaultMetricPrefix, ext.getName(), classesToMethods, true, InstrumentationType.LocalCustomXml, false));
}
return pointCutsOut;
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class YmlExtensionPointCutConverter method createExtensionPointCut.
public static ExtensionClassAndMethodMatcher createExtensionPointCut(Map attrs, String defaultMetricPrefix, ClassLoader classLoader, String extName) {
ClassMatcher classMatcher = getClassMatcher(attrs);
MethodMatcher methodMatcher = getMethodMatcher(attrs);
boolean dispatcher = getDispatcher(attrs);
Config newConfig = new BaseConfig(attrs);
boolean skipTransTrace = newConfig.getProperty(SKIP_TRANS_KEY, Boolean.FALSE);
boolean ignoreTrans = newConfig.getProperty(IGNORE_TRANS_KEY, Boolean.FALSE);
String metricPrefix = defaultMetricPrefix;
String metricName;
Object format = attrs.get(METRIC_NAME_FORMAT_KEY);
if (format instanceof String) {
metricName = format.toString();
} else if (null == format) {
metricName = null;
} else if (format instanceof MetricNameFormatFactory) {
// sorry - not supported anymore
Agent.LOG.log(Level.WARNING, MessageFormat.format("The object property {0} is no longer supported in the agent. The default naming mechanism will be used.", METRIC_NAME_FORMAT_KEY));
metricName = null;
} else {
throw new RuntimeException(MessageFormat.format("Unsupported {0} value", METRIC_NAME_FORMAT_KEY));
}
String tracerFactoryNameString = getTracerFactoryName(attrs, defaultMetricPrefix, dispatcher, format, classLoader);
String nameOfExtension = (extName == null) ? "Unknown" : extName;
return new ExtensionClassAndMethodMatcher(nameOfExtension, metricName, metricPrefix, classMatcher, methodMatcher, dispatcher, skipTransTrace, false, ignoreTrans, tracerFactoryNameString);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class RemoteInstrumentationServiceImpl method updateJvmWithExtension.
private void updateJvmWithExtension(Extension ext, ReinstrumentResult result) {
List<ExtensionClassAndMethodMatcher> pointCuts = null;
if (ext == null || !ext.isEnabled()) {
// remove all if the extension is empty or disabled
pointCuts = Collections.emptyList();
} else {
pointCuts = ExtensionConversionUtility.convertToEnabledPointCuts(Arrays.asList(ext), true, InstrumentationType.RemoteCustomXml, isLiveAttributesEnabled);
}
result.setPointCutsSpecified(pointCuts.size());
// this set of classes to retransform will include any classes that matched the last set of matchers AND
// classes matched with the new matchers
ClassRetransformer remoteRetransformer = ServiceFactory.getClassTransformerService().getRemoteRetransformer();
remoteRetransformer.setClassMethodMatchers(pointCuts);
Class<?>[] allLoadedClasses = ServiceFactory.getCoreService().getInstrumentation().getAllLoadedClasses();
InstrumentationContextClassMatcherHelper matcherHelper = new InstrumentationContextClassMatcherHelper();
Set<Class<?>> classesToRetransform = ClassesMatcher.getMatchingClasses(remoteRetransformer.getMatchers(), matcherHelper, allLoadedClasses);
ReinstrumentUtils.checkClassExistsAndRetransformClasses(result, pointCuts, ext, classesToRetransform);
}
Aggregations