Modify the motan plugin using the new API
This commit is contained in:
parent
82ce2ad225
commit
316c09b012
|
|
@ -1,19 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
|
||||
public enum MotanBuriedPointType implements IBuriedPointType {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "MO";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.SYNC;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.URL;
|
||||
|
||||
/**
|
||||
* Motan client interceptor
|
||||
*/
|
||||
public class MotanClientCallInterceptor implements InstanceMethodsAroundInterceptor{
|
||||
|
||||
private static final String REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
URL url = (URL) context.get(REQUEST_URL);
|
||||
Request request = (Request) interceptorContext.allArguments()[0];
|
||||
if (url != null) {
|
||||
ContextData contextData = new RPCClientInvokeMonitor()
|
||||
.beforeInvoke(generateIdentify(request, url));
|
||||
String contextDataStr = contextData.toString();
|
||||
request.setAttachment("contextData", contextDataStr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
new RPCClientInvokeMonitor().afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
new RPCClientInvokeMonitor().occurException(t);
|
||||
}
|
||||
|
||||
|
||||
private static String generateViewPoint(URL serviceURI, Request request) {
|
||||
StringBuilder viewPoint = new StringBuilder(serviceURI.getUri());
|
||||
viewPoint.append("." + request.getMethodName());
|
||||
viewPoint.append("(" + request.getParamtersDesc() + ")?group=" + serviceURI.getGroup());
|
||||
return viewPoint.toString();
|
||||
}
|
||||
|
||||
|
||||
public static Identification generateIdentify(Request request, URL serviceURI) {
|
||||
return Identification.newBuilder().viewPoint(generateViewPoint(serviceURI, request))
|
||||
.spanType(MotanBuriedPointType.INSTANCE).build();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/23.
|
||||
*/
|
||||
public class MotanClientFetchCallURLInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final String REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
context.set(REQUEST_URL, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.invoke.monitor.RPCServerInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.URL;
|
||||
|
||||
public class MotanServerInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set("serviceURI", interceptorContext.allArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
com.weibo.api.motan.rpc.Request request = (com.weibo.api.motan.rpc.Request) interceptorContext.allArguments()[0];
|
||||
if (request != null) {
|
||||
new RPCServerInvokeMonitor().beforeInvoke(new ContextData(request.getAttachments().get("contextData")),
|
||||
generateIdentify(request, (com.weibo.api.motan.rpc.URL) context.get("serviceURI")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
new RPCServerInvokeMonitor().afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
new RPCServerInvokeMonitor().occurException(t);
|
||||
}
|
||||
|
||||
|
||||
private static String generateViewPoint(URL serviceURI, Request request) {
|
||||
StringBuilder viewPoint = new StringBuilder(serviceURI.getUri());
|
||||
viewPoint.append("." + request.getMethodName());
|
||||
viewPoint.append("(" + request.getParamtersDesc() + ")?group=" + serviceURI.getGroup());
|
||||
return viewPoint.toString();
|
||||
}
|
||||
|
||||
|
||||
public static Identification generateIdentify(Request request, URL serviceURI) {
|
||||
return Identification.newBuilder().viewPoint(generateViewPoint(serviceURI, request))
|
||||
.spanType(MotanBuriedPointType.INSTANCE).build();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.motan.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.weibo.api.motan.cluster.support.ClusterSpi";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("setUrl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanClientFetchCallURLInterceptor";
|
||||
}
|
||||
}, new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("call");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanClientCallInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package com.a.eye.skywalking.api.plugin.motan.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.weibo.api.motan.rpc.AbstractProvider";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanServerInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("call");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.motan.MotanServerInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.a.eye.skywalking.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
/**
|
||||
* {@link ConsumerFetchRequestURLInterceptor} record {@link com.weibo.api.motan.rpc.URL} to {@link EnhancedClassInstanceContext#context}
|
||||
* for the operation name that create span need.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ConsumerFetchRequestURLInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
/**
|
||||
* Fetch the request url from the first param of all constructor, and put request url into {@link EnhancedClassInstanceContext#context}.
|
||||
*
|
||||
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
|
||||
* @param interceptorContext method context, includes class name, method name, etc.
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
*/
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
context.set(CONTEXT_NAME_OF_REQUEST_URL, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package com.a.eye.skywalking.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.Response;
|
||||
import com.weibo.api.motan.rpc.URL;
|
||||
|
||||
/**
|
||||
* {@link ConsumerInvokeInterceptor} create span by fetch request url from {@link EnhancedClassInstanceContext#context} and
|
||||
* transport serialized context data to provider side through {@link Request#setAttachment(String, String)}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ConsumerInvokeInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
/**
|
||||
* Context name of request url in {@link EnhancedClassInstanceContext#context}
|
||||
*/
|
||||
private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
/**
|
||||
* Attachment key of the serialized context data
|
||||
*/
|
||||
private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData";
|
||||
|
||||
/**
|
||||
* Motan component
|
||||
*/
|
||||
private static final String MOTAN_COMPONENT = "Motan";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
URL url = (URL) context.get(CONTEXT_NAME_OF_REQUEST_URL);
|
||||
|
||||
if (url != null) {
|
||||
Request request = (Request) interceptorContext.allArguments()[0];
|
||||
|
||||
Span span = ContextManager.INSTANCE.createSpan(generateOperationName(url, request));
|
||||
Tags.PEER_HOST.set(span, url.getHost());
|
||||
Tags.PEER_PORT.set(span, url.getPort());
|
||||
Tags.COMPONENT.set(span, MOTAN_COMPONENT);
|
||||
Tags.URL.set(span, url.getIdentity());
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
|
||||
Tags.SPAN_LAYER.asRPCFramework(span);
|
||||
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(contextCarrier);
|
||||
request.setAttachment(ATTACHMENT_KEY_OF_CONTEXT_DATA, contextCarrier.serialize());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
Response response = (Response) ret;
|
||||
if (response != null && response.getException() != null) {
|
||||
Span span = ContextManager.INSTANCE.activeSpan();
|
||||
span.log(response.getException());
|
||||
Tags.ERROR.set(span, true);
|
||||
}
|
||||
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
ContextManager.INSTANCE.activeSpan().log(t);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate operation name.
|
||||
*
|
||||
* @return operation name
|
||||
*/
|
||||
private static String generateOperationName(URL serviceURI, Request request) {
|
||||
StringBuilder viewPoint = new StringBuilder(serviceURI.getPath());
|
||||
viewPoint.append("." + request.getMethodName());
|
||||
viewPoint.append("(" + request.getParamtersDesc() + ")");
|
||||
return viewPoint.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.a.eye.skywalking.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.Response;
|
||||
import com.weibo.api.motan.rpc.URL;
|
||||
|
||||
/**
|
||||
* Current trace segment will ref the trace segment from previous level if the serialized context data that fetch
|
||||
* from {@link Request#getAttachments()} is not null.
|
||||
*
|
||||
* {@link ProviderInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for record
|
||||
* the request url from consumer side.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ProviderInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor {
|
||||
|
||||
/**
|
||||
* The key name of request url that stored in {@link EnhancedClassInstanceContext#context}
|
||||
*/
|
||||
private static final String KEY_NAME_OF_REQUEST_URL = "REQUEST_URL";
|
||||
|
||||
/**
|
||||
* The key name that the serialized context data stored in {@link Request#getAttachments()}
|
||||
*/
|
||||
private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData";
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set(KEY_NAME_OF_REQUEST_URL, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
URL url = (URL) context.get(KEY_NAME_OF_REQUEST_URL);
|
||||
if (url != null) {
|
||||
com.weibo.api.motan.rpc.Request request = (com.weibo.api.motan.rpc.Request) interceptorContext.allArguments()[0];
|
||||
Span span = ContextManager.INSTANCE.createSpan(generateViewPoint(url, request));
|
||||
Tags.COMPONENT.set(span, "Motan");
|
||||
Tags.URL.set(span, url.getIdentity());
|
||||
Tags.PEER_PORT.set(span, url.getPort());
|
||||
Tags.PEER_HOST.set(span, url.getHost());
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
|
||||
Tags.SPAN_LAYER.asRPCFramework(span);
|
||||
|
||||
String serializedContextData = request.getAttachments().get(ATTACHMENT_KEY_OF_CONTEXT_DATA);
|
||||
ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(serializedContextData));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
Response response = (Response) ret;
|
||||
if (response != null && response.getException() != null) {
|
||||
Span span = ContextManager.INSTANCE.activeSpan();
|
||||
Tags.ERROR.set(span, true);
|
||||
span.log(response.getException());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
ContextManager.INSTANCE.activeSpan().log(t);
|
||||
}
|
||||
|
||||
|
||||
private static String generateViewPoint(URL serviceURI, Request request) {
|
||||
StringBuilder viewPoint = new StringBuilder(serviceURI.getUri());
|
||||
viewPoint.append("." + request.getMethodName());
|
||||
viewPoint.append("(" + request.getParamtersDesc() + ")");
|
||||
return viewPoint.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.a.eye.skywalking.plugin.motan.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor;
|
||||
import com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* {@link ConsumerInstrumentation} presents that skywalking use {@link ConsumerInvokeInterceptor}
|
||||
* to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use {@link ConsumerFetchRequestURLInterceptor}
|
||||
* to intercept{@link ConsumerFetchRequestURLInterceptor}
|
||||
*/
|
||||
public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "com.weibo.api.motan.cluster.support.ClusterSpi";
|
||||
private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor";
|
||||
private static final String INVOKE_INTECEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor";
|
||||
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return ENHANCE_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("setUrl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return FETCH_REQUEST_URL_INTERCEPT_CLASS;
|
||||
}
|
||||
}, new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("call");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return INVOKE_INTECEPT_CLASS;
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.a.eye.skywalking.plugin.motan.define;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* {@link ProviderInstrumentation} presents that skywalking will use {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor}
|
||||
* to intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class ProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
/**
|
||||
* Enhance class
|
||||
*/
|
||||
private static final String ENHANCE_CLASS = "com.weibo.api.motan.rpc.AbstractProvider";
|
||||
/**
|
||||
* Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}
|
||||
*/
|
||||
private static final String CONSTRUCTOR_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor";
|
||||
/**
|
||||
* Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}
|
||||
*/
|
||||
private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor";
|
||||
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return ENHANCE_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[]{new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return CONSTRUCTOR_INTERCEPT_CLASS;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("call");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return PROVIDER_INVOKE_INTERCEPT_CLASS;
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
com.a.eye.skywalking.plugin.motan.define.MotanClientDefine
|
||||
com.a.eye.skywalking.plugin.motan.define.MotanServerDefine
|
||||
com.a.eye.skywalking.plugin.motan.define.ConsumerInstrumentation
|
||||
com.a.eye.skywalking.plugin.motan.define.ProviderInstrumentation
|
||||
|
|
|
|||
Loading…
Reference in New Issue