Search in sources :

Example 6 with Instrumentor

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

the class PostgreSqlPlugin method addConnectionTransformer.

private void addConnectionTransformer(final PostgreSqlConfig config) {
    transformTemplate.transform("org.postgresql.jdbc4.Jdbc4Connection", 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);
            if (!target.isInterceptable()) {
                return null;
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addInterceptor("com.navercorp.pinpoint.plugin.jdbc.postgresql.interceptor.PostgreSQLConnectionCreateInterceptor");
            target.addScopedInterceptor("com.navercorp.pinpoint.plugin.jdbc.postgresql.interceptor.PostgreSqlPreparedStatementCreateInterceptor3", PostgreSqlConstants.POSTGRESQL_SCOPE);
            return target.toBytecode();
        }
    });
    transformTemplate.transform("org.postgresql.jdbc3.Jdbc3Connection", 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);
            if (!target.isInterceptable()) {
                return null;
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementCreateInterceptor", PostgreSqlConstants.POSTGRESQL_SCOPE);
            return target.toBytecode();
        }
    });
    transformTemplate.transform("org.postgresql.jdbc2.AbstractJdbc2Connection", 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);
            if (!target.isInterceptable()) {
                return null;
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.ConnectionCloseInterceptor", PostgreSqlConstants.POSTGRESQL_SCOPE);
            target.addScopedInterceptor("com.navercorp.pinpoint.plugin.jdbc.postgresql.interceptor.PostgreSqlPreparedStatementCreateInterceptor1", PostgreSqlConstants.POSTGRESQL_SCOPE);
            if (config.isProfileSetAutoCommit()) {
                target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionSetAutoCommitInterceptor", PostgreSqlConstants.POSTGRESQL_SCOPE);
            }
            if (config.isProfileCommit()) {
                target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionCommitInterceptor", PostgreSqlConstants.POSTGRESQL_SCOPE);
            }
            if (config.isProfileRollback()) {
                target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.TransactionRollbackInterceptor", PostgreSqlConstants.POSTGRESQL_SCOPE);
            }
            return target.toBytecode();
        }
    });
    transformTemplate.transform("org.postgresql.jdbc3.AbstractJdbc3Connection", 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);
            if (!target.isInterceptable()) {
                return null;
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.plugin.jdbc.postgresql.interceptor.PostgreSqlPreparedStatementCreateInterceptor2", PostgreSqlConstants.POSTGRESQL_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)

Example 7 with Instrumentor

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

the class HystrixPlugin method addTransformers.

private void addTransformers(int numHystrixCommandAnonymousLocalClass) {
    transformTemplate.transform("com.netflix.hystrix.HystrixCommand", new HystrixCommandTransformer());
    /*
         * After com.netflix.hystrix:hystrix-core:1.4.0 the api changed.
         * The run() and getFallback() methods of the subclass will be called by HystrixCommand's
         * anonymous inner classes.
         *
         * Safest way (although ugly) is to predefine the anonymous inner class names and check each of them to inject
         * their appropriate interceptors as they are loaded.
         *
         * The anonymous inner classes that should be modified may differ according to hystrix-core version. This is
         * simply something that we'll have to keep updating if any changes occur.
         * (Any breaking changes can be detected through integration tests.)
         */
    // number of anonymous inner classes to look for.
    // We start with 3 only because the most recent version requires this many. May be better to make this
    // configurable but for now let's just hard-code it.
    final int numAnonymousInnerClassesToTest = numHystrixCommandAnonymousLocalClass;
    for (int i = 0; i < numAnonymousInnerClassesToTest; ++i) {
        String anonymousInnerClassName = "com.netflix.hystrix.HystrixCommand$" + (i + 1);
        logger.debug("Registering transformer for {}", anonymousInnerClassName);
        transformTemplate.transform(anonymousInnerClassName, 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);
                if (target.hasEnclosingMethod("getExecutionObservable")) {
                    // 1.4.0 ~ 1.5.2 - void call(Subscriber<? super R> s)
                    InstrumentMethod method = target.getDeclaredMethod("call", "rx.Subscriber");
                    // 1.5.3+ - Observable<R> call()
                    if (method == null) {
                        method = target.getDeclaredMethod("call");
                        // 1.5.4+ - May be another anonymous class inside getExecutionObservable()
                        if (!method.getReturnType().equals("rx.Observable")) {
                            return null;
                        }
                    }
                    if (method != null) {
                        // Add getter for the enclosing instance
                        target.addGetter("com.navercorp.pinpoint.plugin.hystrix.field.EnclosingInstanceFieldGetter", "this$0");
                        method.addInterceptor("com.navercorp.pinpoint.plugin.hystrix.interceptor.ExecutionObservableCallInterceptor");
                        return target.toBytecode();
                    } else {
                        logger.warn("Unknown version of HystrixCommand.getExecutionObservable() detected");
                        return null;
                    }
                } else if (target.hasEnclosingMethod("getFallbackObservable")) {
                    // 1.4.0 ~ 1.5.2 - void call(Subscriber<? super R> s)
                    InstrumentMethod method = target.getDeclaredMethod("call", "rx.Subscriber");
                    // 1.5.3+ - Observable<R> call()
                    if (method == null) {
                        method = target.getDeclaredMethod("call");
                    }
                    if (method != null) {
                        // Add getter for the enclosing instance
                        target.addGetter("com.navercorp.pinpoint.plugin.hystrix.field.EnclosingInstanceFieldGetter", "this$0");
                        method.addInterceptor("com.navercorp.pinpoint.plugin.hystrix.interceptor.FallbackObservableCallInterceptor");
                        return target.toBytecode();
                    } else {
                        logger.warn("Unknown version of HystrixCommand.getFallbackObservable detected");
                        return null;
                    }
                } else {
                    return null;
                }
            }
        });
    }
}
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) HystrixCommandTransformer(com.navercorp.pinpoint.plugin.hystrix.transformer.HystrixCommandTransformer)

Example 8 with Instrumentor

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

the class CassandraPlugin method addSessionTransformer.

private void addSessionTransformer(final CassandraConfig config) {
    TransformCallback transformer = 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);
            if (!target.isInterceptable()) {
                return null;
            }
            if (className.equals(CLASS_SESSION_MANAGER)) {
                if (instrumentor.exist(loader, CLASS_ABSTRACT_SESSION)) {
                    return null;
                }
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.plugin.cassandra.interceptor.CassandraConnectionCloseInterceptor", CassandraConstants.CASSANDRA_SCOPE);
            target.addScopedInterceptor("com.navercorp.pinpoint.plugin.cassandra.interceptor.CassandraPreparedStatementCreateInterceptor", CassandraConstants.CASSANDRA_SCOPE);
            target.addScopedInterceptor("com.navercorp.pinpoint.plugin.cassandra.interceptor.CassandraStatementExecuteQueryInterceptor", va(config.getMaxSqlBindValueSize()), CassandraConstants.CASSANDRA_SCOPE);
            return target.toBytecode();
        }
    };
    transformTemplate.transform(CLASS_SESSION_MANAGER, transformer);
    transformTemplate.transform(CLASS_ABSTRACT_SESSION, transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 9 with Instrumentor

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

the class DubboPlugin method addTransformers.

private void addTransformers() {
    transformTemplate.transform("com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker", 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.getDeclaredMethod("invoke", "com.alibaba.dubbo.rpc.Invocation").addInterceptor("com.navercorp.pinpoint.plugin.dubbo.interceptor.DubboConsumerInterceptor");
            return target.toBytecode();
        }
    });
    transformTemplate.transform("com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker", 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.getDeclaredMethod("invoke", "com.alibaba.dubbo.rpc.Invocation").addInterceptor("com.navercorp.pinpoint.plugin.dubbo.interceptor.DubboProviderInterceptor");
            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)

Example 10 with Instrumentor

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

Aggregations

InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)44 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)44 ProtectionDomain (java.security.ProtectionDomain)44 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)42 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)28 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)20 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)5 Method (java.lang.reflect.Method)5 Test (org.junit.Test)5 JavassistClassTest (com.navercorp.pinpoint.test.javasssit.JavassistClassTest)3 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)2 Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)2 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)2 PreparedStatementBindingMethodFilter (com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter)2 List (java.util.List)2 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)1 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)1 HystrixCommandTransformer (com.navercorp.pinpoint.plugin.hystrix.transformer.HystrixCommandTransformer)1