Search in sources :

Example 1 with MethodFilter

use of com.navercorp.pinpoint.bootstrap.instrument.MethodFilter in project pinpoint by naver.

the class MyBatisPlugin method addInterceptorsForSqlSession.

// SqlSession implementations
private void addInterceptorsForSqlSession() {
    final MethodFilter methodFilter = MethodFilters.name("selectOne", "selectList", "selectMap", "select", "insert", "update", "delete");
    final String[] sqlSessionImpls = { "org.apache.ibatis.session.defaults.DefaultSqlSession", "org.mybatis.spring.SqlSessionTemplate" };
    for (final String sqlSession : sqlSessionImpls) {
        transformTemplate.transform(sqlSession, new TransformCallback() {

            @Override
            public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
                final InstrumentClass target = instrumentor.getInstrumentClass(loader, sqlSession, classfileBuffer);
                final List<InstrumentMethod> methodsToTrace = target.getDeclaredMethods(methodFilter);
                for (InstrumentMethod methodToTrace : methodsToTrace) {
                    String sqlSessionOperationInterceptor = "com.navercorp.pinpoint.plugin.mybatis.interceptor.SqlSessionOperationInterceptor";
                    methodToTrace.addScopedInterceptor(sqlSessionOperationInterceptor, MYBATIS_SCOPE, ExecutionPolicy.BOUNDARY);
                }
                return target.toBytecode();
            }
        });
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) List(java.util.List)

Example 2 with MethodFilter

use of com.navercorp.pinpoint.bootstrap.instrument.MethodFilter in project pinpoint by naver.

the class ActiveMQClientPlugin method addProducerEditor.

private void addProducerEditor(final Filter<String> excludeDestinationFilter) {
    final MethodFilter methodFilter = MethodFilters.chain(MethodFilters.name("send"), MethodFilters.argAt(0, "javax.jms.Destination"), MethodFilters.argAt(1, "javax.jms.Message"));
    transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_PRODUCER_FQCN, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            target.addGetter(ActiveMQClientConstants.FIELD_GETTER_ACTIVEMQ_SESSION, ActiveMQClientConstants.FIELD_ACTIVEMQ_MESSAGE_PRODUCER_SESSION);
            for (InstrumentMethod method : target.getDeclaredMethods(methodFilter)) {
                try {
                    method.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_PRODUCER_SEND_INTERCEPTOR_FQCN, va(excludeDestinationFilter));
                } catch (Exception e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Unsupported method " + method, e);
                    }
                }
            }
            return target.toBytecode();
        }
    });
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)

Example 3 with MethodFilter

use of com.navercorp.pinpoint.bootstrap.instrument.MethodFilter in project pinpoint by naver.

the class ASMClass method addInterceptor0.

private int addInterceptor0(TargetFilter annotation, String interceptorClassName, InterceptorScope scope, ExecutionPolicy executionPolicy, Object[] constructorArgs) throws InstrumentException {
    final String filterTypeName = annotation.type();
    Asserts.notNull(filterTypeName, "type of @TargetFilter");
    final InterceptorArgumentProvider interceptorArgumentProvider = objectBinderFactory.newInterceptorArgumentProvider(this);
    final AutoBindingObjectFactory filterFactory = objectBinderFactory.newAutoBindingObjectFactory(pluginContext, classLoader, interceptorArgumentProvider);
    final ObjectFactory objectFactory = ObjectFactory.byConstructor(filterTypeName, (Object[]) annotation.constructorArguments());
    final MethodFilter filter = (MethodFilter) filterFactory.createInstance(objectFactory);
    boolean singleton = annotation.singleton();
    int interceptorId = -1;
    for (InstrumentMethod m : getDeclaredMethods(filter)) {
        if (singleton && interceptorId != -1) {
            m.addInterceptor(interceptorId);
        } else {
            // TODO casting fix
            interceptorId = ((ASMMethod) m).addInterceptorInternal(interceptorClassName, constructorArgs, scope, executionPolicy);
        }
    }
    if (interceptorId == -1) {
        logger.warn("No methods are intercepted. target: " + this.classNode.getInternalName(), ", interceptor: " + interceptorClassName + ", methodFilter: " + filterTypeName);
    }
    return interceptorId;
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory) AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)

Example 4 with MethodFilter

use of com.navercorp.pinpoint.bootstrap.instrument.MethodFilter in project pinpoint by naver.

the class ASMClass method addInterceptor0.

private int addInterceptor0(TargetFilter annotation, Class<? extends Interceptor> interceptorClass, InterceptorScope scope, ExecutionPolicy executionPolicy, Object[] constructorArgs) throws InstrumentException {
    final String filterTypeName = annotation.type();
    Objects.requireNonNull(filterTypeName, "type of @TargetFilter");
    ObjectBinderFactory objectBinderFactory = engineComponent.getObjectBinderFactory();
    final InterceptorArgumentProvider interceptorArgumentProvider = objectBinderFactory.newInterceptorArgumentProvider(this);
    final AutoBindingObjectFactory filterFactory = objectBinderFactory.newAutoBindingObjectFactory(pluginContext, classNode.getClassLoader(), interceptorArgumentProvider);
    final ObjectFactory objectFactory = ObjectFactory.byConstructor(filterTypeName, (Object[]) annotation.constructorArguments());
    final MethodFilter filter = (MethodFilter) filterFactory.createInstance(objectFactory);
    boolean singleton = annotation.singleton();
    int interceptorId = -1;
    for (InstrumentMethod m : getDeclaredMethods(filter)) {
        if (singleton && interceptorId != -1) {
            m.addInterceptor(interceptorId);
        } else {
            // TODO casting fix
            interceptorId = ((ASMMethod) m).addInterceptorInternal(interceptorClass, constructorArgs, scope, executionPolicy);
        }
    }
    if (interceptorId == -1) {
        logger.warn("No methods are intercepted. target:{}, interceptor:{}, methodFilter:{} ", this.classNode.getInternalName(), interceptorClass, filterTypeName);
    }
    return interceptorId;
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory) AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) ObjectBinderFactory(com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)

Example 5 with MethodFilter

use of com.navercorp.pinpoint.bootstrap.instrument.MethodFilter in project pinpoint by naver.

the class TargetAnnotatedInterceptorInjector method createFilteredMethodEditor.

private MethodTransformer createFilteredMethodEditor(TargetFilter annotation, InstrumentClass targetClass, AnnotatedInterceptorInjector injector, ClassLoader classLoader) {
    String type = annotation.type();
    if (type == null) {
        throw new PinpointException("type of @TargetFilter is null: " + interceptorClassName);
    }
    final InterceptorArgumentProvider interceptorArgumentProvider = new InterceptorArgumentProvider(dataSourceMonitorRegistry, apiMetaDataService, targetClass);
    AutoBindingObjectFactory filterFactory = new AutoBindingObjectFactory(profilerConfig, traceContext, pluginContext, classLoader, interceptorArgumentProvider);
    MethodFilter filter = (MethodFilter) filterFactory.createInstance(ObjectFactory.byConstructor(type, (Object[]) annotation.constructorArguments()));
    MethodRecipe recipe = annotation.singleton() ? new SharedAnnotatedInterceptorInjector(injector) : injector;
    return new FilteringMethodTransformer(new MethodFilter[] { filter }, Arrays.<MethodRecipe>asList(recipe), null);
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) MethodRecipe(com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodRecipe) PinpointException(com.navercorp.pinpoint.exception.PinpointException) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) FilteringMethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer)

Aggregations

MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)5 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)4 AutoBindingObjectFactory (com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory)3 InterceptorArgumentProvider (com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider)3 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)2 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)2 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)2 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)2 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)2 ProtectionDomain (java.security.ProtectionDomain)2 PinpointException (com.navercorp.pinpoint.exception.PinpointException)1 ObjectBinderFactory (com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory)1 FilteringMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer)1 MethodRecipe (com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodRecipe)1 List (java.util.List)1