Search in sources :

Example 26 with InstrumentException

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

the class ThriftPlugin method addProcessFunctionEditor.

private void addProcessFunctionEditor() {
    final String targetClassName = "org.apache.thrift.ProcessFunction";
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SERVER_MARKER_FLAG);
            // ProcessFunction.process(int, TProtocol, TProtocol, I)
            final InstrumentMethod process = target.getDeclaredMethod("process", "int", "org.apache.thrift.protocol.TProtocol", "org.apache.thrift.protocol.TProtocol", "java.lang.Object");
            if (process != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.ProcessFunctionProcessInterceptor";
                process.addInterceptor(interceptor);
            }
            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 27 with InstrumentException

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

the class ThriftPlugin method addTNonblockingSocketEditor.

private void addTNonblockingSocketEditor() {
    final String targetClassName = "org.apache.thrift.transport.TNonblockingSocket";
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET_ADDRESS);
            // TNonblockingSocket(SocketChannel, int, SocketAddress)
            final InstrumentMethod constructor = target.getConstructor("java.nio.channels.SocketChannel", "int", "java.net.SocketAddress");
            if (constructor != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.TNonblockingSocketConstructInterceptor";
                constructor.addInterceptor(interceptor);
            }
            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 28 with InstrumentException

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

the class BeanMethodTransformer method doInTransform.

@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
    try {
        final InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
        if (!target.isInterceptable()) {
            return null;
        }
        final List<InstrumentMethod> methodList = target.getDeclaredMethods(METHOD_FILTER);
        for (InstrumentMethod method : methodList) {
            addInterceptor(method);
        }
        return target.toBytecode();
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to spring beans modify. Cause:{}", e.getMessage(), e);
        }
        return null;
    }
}
Also used : InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)

Example 29 with InstrumentException

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

the class ThriftPlugin method addTTransportEditor.

private void addTTransportEditor(String tTransportClassName, final String tTransportInterceptorFqcn, final String[]... parameterTypeGroups) {
    final String targetClassName = tTransportClassName;
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET);
            for (String[] parameterTypeGroup : parameterTypeGroups) {
                final InstrumentMethod constructor = target.getConstructor(parameterTypeGroup);
                if (constructor != null) {
                    constructor.addInterceptor(tTransportInterceptorFqcn);
                }
            }
            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 30 with InstrumentException

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

the class ThriftPlugin method addTBaseAsyncProcessorEditor.

private void addTBaseAsyncProcessorEditor() {
    final String targetClassName = "org.apache.thrift.TBaseAsyncProcessor";
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SERVER_MARKER_FLAG);
            target.addField(ThriftConstants.FIELD_ACCESSOR_ASYNC_MARKER_FLAG);
            // TBaseAsyncProcessor.process(AbstractNonblockingServer$AsyncFrameBuffer)
            final InstrumentMethod process = target.getDeclaredMethod("process", "org.apache.thrift.server.AbstractNonblockingServer$AsyncFrameBuffer");
            if (process != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.async.TBaseAsyncProcessorProcessInterceptor";
                process.addInterceptor(interceptor);
            }
            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)

Aggregations

InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)35 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)29 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)28 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)28 ProtectionDomain (java.security.ProtectionDomain)28 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)22 Method (java.lang.reflect.Method)6 Test (org.junit.Test)6 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)5 NotFoundInstrumentException (com.navercorp.pinpoint.bootstrap.instrument.NotFoundInstrumentException)3 PinpointException (com.navercorp.pinpoint.exception.PinpointException)3 JavassistClassTest (com.navercorp.pinpoint.test.javasssit.JavassistClassTest)3 List (java.util.List)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 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)1 PreparedStatementBindingMethodFilter (com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter)1