Search in sources :

Example 6 with InstrumentClass

use of com.shulie.instrument.simulator.api.instrument.InstrumentClass in project LinkAgent by shulieTech.

the class JdkHttpPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, "sun.net.www.protocol.http.HttpURLConnection", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.includeBootstrap();
            final InstrumentMethod connectMethod = target.getDeclaredMethod("connect");
            connectMethod.addInterceptor(Listeners.of(HttpURLConnectionInterceptor.class, "JDK_HTTP_HTTPURLCONNECTION_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            final InstrumentMethod getInputStreamMethod = target.getDeclaredMethod("getInputStream");
            getInputStreamMethod.addInterceptor(Listeners.of(HttpURLConnectionGetInputStreamInterceptor.class, "JDK_HTTP_HTTPURLCONNECTION_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            final InstrumentMethod getOutputStreamMethod = target.getDeclaredMethod("getOutputStream");
            getOutputStreamMethod.addInterceptor(Listeners.of(HttpURLConnectionInterceptor.class, "JDK_HTTP_HTTPURLCONNECTION_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    enhanceTemplate.enhance(this, "sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.includeBootstrap();
            final InstrumentMethod connectMethod = target.getDeclaredMethod("connect");
            connectMethod.addInterceptor(Listeners.of(HttpURLConnectionInterceptor.class, "JDK_HTTP_HTTPS_URLCONNECTION_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    enhanceTemplate.enhance(this, "sun.net.www.http.HttpClient", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.includeBootstrap();
            InstrumentMethod method = target.getDeclaredMethod("writeRequests", "sun.net.www.MessageHeader", "sun.net.www.http.PosterOutputStream", "boolean");
            method.addInterceptor(Listeners.of(HttpClientInterceptor.class));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 7 with InstrumentClass

use of com.shulie.instrument.simulator.api.instrument.InstrumentClass in project LinkAgent by shulieTech.

the class RabbitMQPlugin method addHookRegisterInterceptor.

private boolean addHookRegisterInterceptor() {
    if (simulatorConfig.getBooleanProperty("auto.create.queue.rabbitmq", false)) {
        this.enhanceTemplate.enhance(this, "org.springframework.amqp.rabbit.core.RabbitAdmin", new EnhanceCallback() {

            @Override
            public void doEnhance(InstrumentClass target) {
                InstrumentMethod handle = target.getDeclaredMethod("declareQueue", "org.springframework.amqp.core.Queue");
                handle.addInterceptor(Listeners.of(SpringRabbitRabbitAdminDeclareQueueInterceptor.class));
            }
        });
    }
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.impl.AMQConnection", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.getDeclaredMethods("close").addInterceptor(Listeners.of(AMQConnectionInterceptor.class));
        }
    });
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.impl.StrictExceptionHandler", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.getDeclaredMethods("handleConsumerException").addInterceptor(Listeners.of(StrictExceptionHandlerInterceptor.class));
        }
    });
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.impl.ConsumerDispatcher", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.getDeclaredMethods("notifyConsumerOfShutdown").addInterceptor(Listeners.of(NotifyConsumerOfShutdownInterceptor.class));
        }
    });
    // 增强channel
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.impl.ChannelN", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod basicPublishMethod = target.getDeclaredMethod("basicPublish", "java.lang.String", "java.lang.String", "boolean", "boolean", "com.rabbitmq.client.AMQP$BasicProperties", "byte[]");
            basicPublishMethod.addInterceptor(Listeners.of(ChannelNBasicPublishInterceptor.class));
            final InstrumentMethod basicGetMethod = target.getDeclaredMethod("basicGet", "java.lang.String", "boolean");
            basicGetMethod.addInterceptor(Listeners.of(ChannelNBasicGetInterceptor.class));
            final InstrumentMethod processDeliveryMethod = target.getDeclaredMethod("processDelivery", "com.rabbitmq.client.Command", "com.rabbitmq.client.impl.AMQImpl$Basic$Deliver");
            processDeliveryMethod.addInterceptor(Listeners.of(ChannelNProcessDeliveryInterceptor.class, new Object[] { simulatorConfig }));
            final InstrumentMethod basicCancelMethod = target.getDeclaredMethod("basicCancel", "java.lang.String");
            basicCancelMethod.addInterceptor(Listeners.of(ChannelNBasicCancelInterceptor.class));
            addAckInterceptor(target);
        }
    });
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.impl.recovery.RecoveryAwareChannelN", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            addAckInterceptor(target);
        }
    });
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.impl.ChannelN", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            addAckInterceptor(target);
        }
    });
    // 异步Consumer,作用是打标&trace
    this.enhanceTemplate.enhance(this, "com.rabbitmq.client.QueueingConsumer", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod handle = target.getDeclaredMethod("handle", "com.rabbitmq.client.QueueingConsumer$Delivery");
            handle.addInterceptor(Listeners.of(QueueingConsumerHandleInterceptor.class));
        }
    });
    // spring 是异步消费的,这里只保留trace相关interceptor,消费者注册逻辑与原生合并see SpringConsumerMetaDataBuilder
    if (simulatorConfig.getBooleanProperty("auto.create.queue.rabbitmq", false)) {
        this.enhanceTemplate.enhance(this, "org.springframework.amqp.rabbit.core.RabbitAdmin", new EnhanceCallback() {

            @Override
            public void doEnhance(InstrumentClass target) {
                InstrumentMethod handle = target.getDeclaredMethod("declareQueue", "org.springframework.amqp.core.Queue");
                handle.addInterceptor(Listeners.of(SpringRabbitRabbitAdminDeclareQueueInterceptor.class));
            }
        });
    }
    this.enhanceTemplate.enhance(this, "org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethod("executeListener", "com.rabbitmq.client.Channel", "org.springframework.amqp.core.Message");
            method.addInterceptor(Listeners.of(SpringBlockingQueueConsumerDeliveryInterceptor.class));
            InstrumentMethod method1 = target.getDeclaredMethod("executeListener", "com.rabbitmq.client.Channel", "java.lang.Object");
            method1.addInterceptor(Listeners.of(SpringBlockingQueueConsumerDeliveryInterceptor.class));
        }
    });
    // });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 8 with InstrumentClass

use of com.shulie.instrument.simulator.api.instrument.InstrumentClass in project LinkAgent by shulieTech.

the class PulsarPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, "org.apache.pulsar.client.impl.ProducerImpl", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethod("sendAsync", "org.apache.pulsar.client.api.Message", "org.apache.pulsar.client.impl.SendCallback");
            method.addInterceptor(Listeners.of(PulsarTraceProducerInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "org.apache.pulsar.client.impl.ConsumerBase", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethod("beforeConsume", "org.apache.pulsar.client.api.Message");
            method.addInterceptor(Listeners.of(PulsarTraceConsumerInterceptor.class));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 9 with InstrumentClass

use of com.shulie.instrument.simulator.api.instrument.InstrumentClass in project LinkAgent by shulieTech.

the class WebspherePlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, "com.ibm.ws.webcontainer.srt.SRTServletRequest", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod startAsyncMethodEditor = target.getDeclaredMethod("startAsync", "javax.servlet.ServletRequest", "javax.servlet.ServletResponse");
            if (startAsyncMethodEditor != null) {
                startAsyncMethodEditor.addInterceptor(Listeners.of(SRTServletRequestStartAsyncInterceptor.class));
            }
        }
    });
    enhanceTemplate.enhance(this, "com.ibm.ws.webcontainer.WSWebContainer", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod handleMethodEditorBuilder = target.getDeclaredMethod("handleRequest", "com.ibm.websphere.servlet.request.IRequest", "com.ibm.websphere.servlet.response.IResponse");
            handleMethodEditorBuilder.addInterceptor(Listeners.of(WebContainerHandleRequestInterceptor.class));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 10 with InstrumentClass

use of com.shulie.instrument.simulator.api.instrument.InstrumentClass in project LinkAgent by shulieTech.

the class ApacheDubboPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    this.enhanceTemplate.enhance(this, "org.apache.dubbo.rpc.protocol.AbstractInvoker", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod invokeMethod = target.getDeclaredMethod("invoke", "org.apache.dubbo.rpc.Invocation");
            if (invokeMethod != null) {
                invokeMethod.addInterceptor(Listeners.of(DubboConsumerInterceptor.class));
            }
        }
    });
    // 最终都会执行 AbstractInvoker, 不需要拦截filter。ConsumerContextFilterInterceptor 只实现了拦截,不记录trace
    // this.enhanceTemplate.enhance(this, "org.apache.dubbo.rpc.filter.ConsumerContextFilter", new EnhanceCallback() {
    // @Override
    // public void doEnhance(InstrumentClass target) {
    // final InstrumentMethod invokeMethod = target.getDeclaredMethod("invoke", "org.apache.dubbo.rpc.Invoker", "org.apache.dubbo.rpc.Invocation");
    // if (invokeMethod != null) {
    // invokeMethod
    // .addInterceptor(Listeners.of(ConsumerContextFilterInterceptor.class));
    // }
    // }
    // });
    this.enhanceTemplate.enhance(this, "org.apache.dubbo.rpc.proxy.AbstractProxyInvoker", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod invokeMethod = target.getDeclaredMethod("invoke", "org.apache.dubbo.rpc.Invocation");
            if (invokeMethod != null) {
                invokeMethod.addInterceptor(Listeners.of(DubboProviderInterceptor.class));
            }
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Aggregations

EnhanceCallback (com.shulie.instrument.simulator.api.instrument.EnhanceCallback)42 InstrumentClass (com.shulie.instrument.simulator.api.instrument.InstrumentClass)42 InstrumentMethod (com.shulie.instrument.simulator.api.instrument.InstrumentMethod)41 XxlJobAdapter (com.pamirs.attach.plugin.shadowjob.adapter.XxlJobAdapter)1 IEvent (com.pamirs.pradar.pressurement.agent.event.IEvent)1 ClusterTestSwitchOffEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)1 ClusterTestSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent)1 EventResult (com.pamirs.pradar.pressurement.agent.listener.EventResult)1 PradarEventListener (com.pamirs.pradar.pressurement.agent.listener.PradarEventListener)1 ShadowImplListener (com.pamirs.pradar.pressurement.agent.listener.impl.ShadowImplListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1