DefaultHttpClientInstrumentation.java 2.0 KB
Newer Older
1
package org.skywalking.apm.plugin.feign.http.v9.define;
2 3 4 5 6 7

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
8
import org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor;
9 10 11 12

import static net.bytebuddy.matcher.ElementMatchers.named;

/**
13 14 15 16
 * {@link DefaultHttpClientInstrumentation} presents that skywalking intercepts {@link
 * feign.Client.Default#execute(feign.Request, feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}.
 * If feign did't run in default mode, the instrumentation depend on the http client implementation.
 * e.g. okhttp client implementation depend on okhttp-plugin.
17 18 19
 *
 * @author pengys5
 */
20
public class DefaultHttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
21 22 23 24

    /**
     * Enhance class.
     */
25
    private static final String ENHANCE_CLASS = "feign.Client$Default";
26 27 28 29

    /**
     * Intercept class.
     */
30
    private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor";
31 32 33 34 35 36

    @Override protected String enhanceClassName() {
        return ENHANCE_CLASS;
    }

    @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
37
        return new ConstructorInterceptPoint[0];
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    }

    @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
        return new InstanceMethodsInterceptPoint[] {
            new InstanceMethodsInterceptPoint() {
                @Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
                    return named("execute");
                }

                @Override public String getMethodsInterceptor() {
                    return INTERCEPT_CLASS;
                }
            }
        };
    }
}