Search in sources :

Example 6 with InstrumentMethod

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod 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 7 with InstrumentMethod

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

the class GsonPlugin method setup.

@Override
public void setup(ProfilerPluginSetupContext context) {
    GsonConfig config = new GsonConfig(context.getConfig());
    logger.debug("[Gson] Initialized config={}", config);
    if (config.isProfile()) {
        transformTemplate.transform("com.google.gson.Gson", 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);
                for (InstrumentMethod m : target.getDeclaredMethods(MethodFilters.name("fromJson"))) {
                    m.addScopedInterceptor("com.navercorp.pinpoint.plugin.gson.interceptor.FromJsonInterceptor", GSON_SCOPE);
                }
                for (InstrumentMethod m : target.getDeclaredMethods(MethodFilters.name("toJson"))) {
                    m.addScopedInterceptor("com.navercorp.pinpoint.plugin.gson.interceptor.ToJsonInterceptor", GSON_SCOPE);
                }
                return target.toBytecode();
            }
        });
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) 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)

Example 8 with InstrumentMethod

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

the class DedicatedMethodTransformer method edit.

@Override
public void edit(ClassLoader classLoader, InstrumentClass target) throws Throwable {
    InstrumentMethod targetMethod = target.getDeclaredMethod(targetMethodName, targetMethodParameterTypes);
    if (targetMethod == null) {
        if (ignoreIfNotExist) {
            return;
        } else {
            Exception e = new NoSuchMethodException("No such method: " + targetMethodName + "(" + Arrays.deepToString(targetMethodParameterTypes) + ")");
            if (exceptionHandler != null) {
                exceptionHandler.handle(target.getName(), targetMethodName, targetMethodParameterTypes, e);
                logger.info("Cannot find target method" + targetMethodName + "(" + Arrays.deepToString(targetMethodParameterTypes) + ") but MethodTransformerExceptionHandler handled it.");
                return;
            } else {
                throw new InstrumentException("Fail to edit method", e);
            }
        }
    }
    for (MethodRecipe recipe : recipes) {
        try {
            recipe.edit(classLoader, target, targetMethod);
        } catch (Throwable t) {
            if (exceptionHandler != null) {
                exceptionHandler.handle(target.getName(), targetMethodName, targetMethodParameterTypes, t);
                logger.info("Exception thrown while editing" + targetMethod.getDescriptor().getApiDescriptor() + " but MethodTransformerExceptionHandler handled it.", t);
            } else {
                throw new InstrumentException("Fail to edit method " + targetMethod.getDescriptor().getApiDescriptor(), t);
            }
        }
    }
}
Also used : InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)

Example 9 with InstrumentMethod

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

the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor3_NoCatchClause.

@Test
public void testGenerate_AroundInterceptor3_NoCatchClause() throws Exception {
    final Class<AroundInterceptor3> aroundInterceptor3Class = AroundInterceptor3.class;
    final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
    final InstrumentClass mockClass = mock(InstrumentClass.class);
    Mockito.when(mockClass.getName()).thenReturn("TestClass");
    final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
    Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
    Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] { "java.lang.Object", "java.lang.Object", "java.lang.Object" });
    Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
    ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
    final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, false);
    final String generate = invokeAfterCodeGenerator.generate();
    logger.debug("testGenerate_AroundInterceptor3_NoCatchClause:{}", generate);
    Assert.assertTrue(generate.contains("($w)$1"));
    Assert.assertTrue(generate.contains("($w)$2"));
    Assert.assertTrue(generate.contains("($w)$3"));
    Assert.assertTrue(generate.contains("($w)$_"));
}
Also used : AroundInterceptor3(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) Test(org.junit.Test)

Example 10 with InstrumentMethod

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod 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)

Aggregations

InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)33 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)29 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)21 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)19 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)19 ProtectionDomain (java.security.ProtectionDomain)19 Test (org.junit.Test)9 ApiMetaDataService (com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)6 AroundInterceptor3 (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3)4 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)3 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)3 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)3 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)3 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 List (java.util.List)2 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 AroundInterceptor0 (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor0)1 Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)1