Search in sources :

Example 21 with ExtensionClassAndMethodMatcher

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);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) LinkedList(java.util.LinkedList)

Example 22 with ExtensionClassAndMethodMatcher

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;
}
Also used : Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList)

Example 23 with ExtensionClassAndMethodMatcher

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;
}
Also used : Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation)

Example 24 with ExtensionClassAndMethodMatcher

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);
}
Also used : ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) BaseConfig(com.newrelic.agent.config.BaseConfig) Config(com.newrelic.agent.config.Config) BaseConfig(com.newrelic.agent.config.BaseConfig) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)

Example 25 with ExtensionClassAndMethodMatcher

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);
}
Also used : ClassRetransformer(com.newrelic.agent.instrumentation.custom.ClassRetransformer) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) InstrumentationContextClassMatcherHelper(com.newrelic.agent.instrumentation.context.InstrumentationContextClassMatcherHelper)

Aggregations

ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)36 Test (org.junit.Test)26 Extension (com.newrelic.agent.extension.beans.Extension)11 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)10 ArrayList (java.util.ArrayList)10 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)9 Instrumentation (com.newrelic.agent.extension.beans.Extension.Instrumentation)8 File (java.io.File)6 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LinkedList (java.util.LinkedList)5 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)4 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)3 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)3 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)2 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1