Merge branch 'master' into zhangxin/feature/support-rest-template
This commit is contained in:
commit
e52acd2bcc
|
|
@ -12,7 +12,7 @@ service JVMMetricsService {
|
|||
|
||||
message JVMMetrics {
|
||||
repeated JVMMetric metrics = 1;
|
||||
int64 applicationInstanceId = 2;
|
||||
int32 applicationInstanceId = 2;
|
||||
}
|
||||
|
||||
message JVMMetric {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public abstract class AbstractClassEnhancePluginDefine {
|
|||
logger.debug("prepare to enhance class {} by {}.", transformClassName, interceptorDefineClassName);
|
||||
|
||||
/**
|
||||
* findOrPrepare4Register witness classes for enhance class
|
||||
* find witness classes for enhance class
|
||||
*/
|
||||
String[] witnessClasses = witnessClasses();
|
||||
if (witnessClasses != null) {
|
||||
|
|
@ -51,7 +51,7 @@ public abstract class AbstractClassEnhancePluginDefine {
|
|||
}
|
||||
|
||||
/**
|
||||
* findOrPrepare4Register origin class source code for interceptor
|
||||
* find origin class source code for interceptor
|
||||
*/
|
||||
DynamicType.Builder<?> newClassBuilder = this.enhance(transformClassName, builder, classLoader);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
/**
|
||||
* The <code>PluginFinder</code> represents a finder , which assist to findOrPrepare4Register the one
|
||||
* The <code>PluginFinder</code> represents a finder , which assist to find the one
|
||||
* from the given {@link AbstractClassEnhancePluginDefine} list.
|
||||
*
|
||||
* @author wusheng
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class PluginResourcesResolver {
|
|||
while (urls.hasMoreElements()) {
|
||||
URL pluginUrl = urls.nextElement();
|
||||
cfgUrlPaths.add(pluginUrl);
|
||||
logger.info("findOrPrepare4Register skywalking plugin define in {}", pluginUrl);
|
||||
logger.info("find skywalking plugin define in {}", pluginUrl);
|
||||
}
|
||||
|
||||
return cfgUrlPaths;
|
||||
|
|
@ -42,7 +42,7 @@ public class PluginResourcesResolver {
|
|||
* First get current thread's classloader,
|
||||
* if fail, get {@link PluginResourcesResolver}'s classloader.
|
||||
*
|
||||
* @return the classloader to findOrPrepare4Register plugin definitions.
|
||||
* @return the classloader to find plugin definitions.
|
||||
*/
|
||||
private ClassLoader getDefaultClassLoader() {
|
||||
ClassLoader cl = null;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class InstMethodsInter {
|
|||
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||
interceptor.beforeMethod(targetObject, method, allArguments, method.getParameterTypes(),
|
||||
result);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] before method[{}] intercept failure", obj.getClass(), method.getName());
|
||||
|
|
@ -72,7 +72,7 @@ public class InstMethodsInter {
|
|||
}
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
interceptor.handleMethodException(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||
interceptor.handleMethodException(targetObject, method, allArguments, method.getParameterTypes(),
|
||||
t);
|
||||
} catch (Throwable t2) {
|
||||
logger.error(t2, "class[{}] handle method[{}] exception failure", obj.getClass(), method.getName());
|
||||
|
|
@ -80,7 +80,7 @@ public class InstMethodsInter {
|
|||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||
ret = interceptor.afterMethod(targetObject, method, allArguments, method.getParameterTypes(),
|
||||
ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] after method[{}] intercept failure", obj.getClass(), method.getName());
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class InstMethodsInterWithOverrideArgs {
|
|||
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||
interceptor.beforeMethod(targetObject, method, allArguments, method.getParameterTypes(),
|
||||
result);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] before method[{}] intercept failure", obj.getClass(), method.getName());
|
||||
|
|
@ -74,7 +74,7 @@ public class InstMethodsInterWithOverrideArgs {
|
|||
}
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
interceptor.handleMethodException(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||
interceptor.handleMethodException(targetObject, method, allArguments, method.getParameterTypes(),
|
||||
t);
|
||||
} catch (Throwable t2) {
|
||||
logger.error(t2, "class[{}] handle method[{}] exception failure", obj.getClass(), method.getName());
|
||||
|
|
@ -82,7 +82,7 @@ public class InstMethodsInterWithOverrideArgs {
|
|||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(targetObject, method.getName(), allArguments, method.getParameterTypes(),
|
||||
ret = interceptor.afterMethod(targetObject, method, allArguments, method.getParameterTypes(),
|
||||
ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] after method[{}] intercept failure", obj.getClass(), method.getName());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.skywalking.apm.agent.core.plugin.interceptor.enhance;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* A interceptor, which intercept method's invocation. The target methods will be defined in {@link
|
||||
* ClassEnhancePluginDefine}'s subclass, most likely in {@link ClassInstanceMethodsEnhancePluginDefine}
|
||||
|
|
@ -10,27 +12,32 @@ public interface InstanceMethodsAroundInterceptor {
|
|||
/**
|
||||
* called before target method invocation.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
* @throws Throwable
|
||||
*/
|
||||
void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) throws Throwable;
|
||||
|
||||
/**
|
||||
* called after target method invocation. Even method's invocation triggers an exception.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param ret the method's original return value.
|
||||
* @return the method's actual return value.
|
||||
* @throws Throwable
|
||||
*/
|
||||
Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable;
|
||||
|
||||
/**
|
||||
* called when occur exception.
|
||||
*
|
||||
* @param method
|
||||
* @param t the exception occur.
|
||||
*/
|
||||
void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Throwable t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.skywalking.apm.agent.core.plugin.interceptor.enhance;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* The static method's interceptor interface.
|
||||
* Any plugin, which wants to intercept static methods, must implement this interface.
|
||||
|
|
@ -10,24 +12,28 @@ public interface StaticMethodsAroundInterceptor {
|
|||
/**
|
||||
* called before target method invocation.
|
||||
*
|
||||
* @param method
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
*/
|
||||
void beforeMethod(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
MethodInterceptResult result);
|
||||
|
||||
/**
|
||||
* called after target method invocation. Even method's invocation triggers an exception.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param ret the method's original return value.
|
||||
* @return the method's actual return value.
|
||||
*/
|
||||
Object afterMethod(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes, Object ret);
|
||||
Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Object ret);
|
||||
|
||||
/**
|
||||
* called when occur exception.
|
||||
*
|
||||
* @param method
|
||||
* @param t the exception occur.
|
||||
*/
|
||||
void handleMethodException(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Throwable t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class StaticMethodsInter {
|
|||
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(clazz, method.getName(), allArguments, method.getParameterTypes(), result);
|
||||
interceptor.beforeMethod(clazz, method, allArguments, method.getParameterTypes(), result);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] before static method[{}] intercept failure", clazz, method.getName());
|
||||
}
|
||||
|
|
@ -69,14 +69,14 @@ public class StaticMethodsInter {
|
|||
}
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
interceptor.handleMethodException(clazz, method.getName(), allArguments, method.getParameterTypes(), t);
|
||||
interceptor.handleMethodException(clazz, method, allArguments, method.getParameterTypes(), t);
|
||||
} catch (Throwable t2) {
|
||||
logger.error(t2, "class[{}] handle static method[{}] exception failure", clazz, method.getName(), t2.getMessage());
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(clazz, method.getName(), allArguments, method.getParameterTypes(), ret);
|
||||
ret = interceptor.afterMethod(clazz, method, allArguments, method.getParameterTypes(), ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] after static method[{}] intercept failure:{}", clazz, method.getName(), t.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class StaticMethodsInterWithOverrideArgs {
|
|||
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(clazz, method.getName(), allArguments, method.getParameterTypes(), result);
|
||||
interceptor.beforeMethod(clazz, method, allArguments, method.getParameterTypes(), result);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] before static method[{}] intercept failure", clazz, method.getName());
|
||||
}
|
||||
|
|
@ -67,14 +67,14 @@ public class StaticMethodsInterWithOverrideArgs {
|
|||
}
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
interceptor.handleMethodException(clazz, method.getName(), allArguments, method.getParameterTypes(), t);
|
||||
interceptor.handleMethodException(clazz, method, allArguments, method.getParameterTypes(), t);
|
||||
} catch (Throwable t2) {
|
||||
logger.error(t2, "class[{}] handle static method[{}] exception failure", clazz, method.getName(), t2.getMessage());
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(clazz, method.getName(), allArguments, method.getParameterTypes(), ret);
|
||||
ret = interceptor.afterMethod(clazz, method, allArguments, method.getParameterTypes(), ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t, "class[{}] after static method[{}] intercept failure:{}", clazz, method.getName(), t.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alibaba.dubbo.rpc.Invocation;
|
|||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.Result;
|
||||
import com.alibaba.dubbo.rpc.RpcContext;
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -40,7 +41,7 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
* {@link RpcContext#attachments}. current trace segment will ref if the serialize context data is not null.
|
||||
*/
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Invoker invoker = (Invoker)allArguments[0];
|
||||
Invocation invocation = (Invocation)allArguments[1];
|
||||
|
|
@ -80,7 +81,7 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Result result = (Result)ret;
|
||||
if (result != null && result.getException() != null) {
|
||||
|
|
@ -92,7 +93,7 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
dealException(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ public class DubboInterceptorTest {
|
|||
public void testConsumerBelow283() throws Throwable {
|
||||
BugFixActive.active();
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -113,8 +113,8 @@ public class DubboInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testConsumerWithAttachment() throws Throwable {
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -125,9 +125,9 @@ public class DubboInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testConsumerWithException() throws Throwable {
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.handleMethodException(enhancedInstance, "invoke", allArguments, argumentTypes, new RuntimeException());
|
||||
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException());
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
assertConsumerTraceSegmentInErrorCase(traceSegment);
|
||||
|
|
@ -137,8 +137,8 @@ public class DubboInterceptorTest {
|
|||
public void testConsumerWithResultHasException() throws Throwable {
|
||||
when(result.getException()).thenReturn(new RuntimeException());
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -150,8 +150,8 @@ public class DubboInterceptorTest {
|
|||
when(rpcContext.isConsumerSide()).thenReturn(false);
|
||||
when(rpcContext.getAttachment(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
assertProvider();
|
||||
}
|
||||
|
||||
|
|
@ -162,8 +162,8 @@ public class DubboInterceptorTest {
|
|||
|
||||
testParam.setTraceContext("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, "invoke", allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, "invoke", allArguments, argumentTypes, result);
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
assertProvider();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.skywalking.apm.plugin.feign.http.v9;
|
|||
import feign.Request;
|
||||
import feign.Response;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -36,10 +37,12 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc
|
|||
* port, kind, component, url from {@link feign.Request}.
|
||||
* Through the reflection of the way, set the http header of context data into {@link feign.Request#headers}.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Request request = (Request)allArguments[0];
|
||||
|
||||
|
|
@ -73,11 +76,13 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc
|
|||
* the server.
|
||||
* Finish the {@link AbstractSpan}.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param ret the method's original return value.
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Response response = (Response)ret;
|
||||
int statusCode = response.status();
|
||||
|
|
@ -93,7 +98,7 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
activeSpan.log(t);
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ public class DefaultHttpClientInterceptorTest {
|
|||
public void testMethodsAround() throws Throwable {
|
||||
Response response = mock(Response.class);
|
||||
when(response.status()).thenReturn(200);
|
||||
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentTypes, result);
|
||||
defaultHttpClientInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentTypes, response);
|
||||
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -101,11 +101,11 @@ public class DefaultHttpClientInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testMethodsAroundError() throws Throwable {
|
||||
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentTypes, result);
|
||||
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
Response response = mock(Response.class);
|
||||
when(response.status()).thenReturn(404);
|
||||
defaultHttpClientInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentTypes, response);
|
||||
defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -130,13 +130,13 @@ public class DefaultHttpClientInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testException() throws Throwable {
|
||||
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentTypes, result);
|
||||
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
defaultHttpClientInterceptor.handleMethodException(enhancedInstance, "execute", allArguments, argumentTypes, new NullPointerException("testException"));
|
||||
defaultHttpClientInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException"));
|
||||
|
||||
Response response = mock(Response.class);
|
||||
when(response.status()).thenReturn(200);
|
||||
defaultHttpClientInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentTypes, response);
|
||||
defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.plugin.httpClient.v4;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import org.apache.http.HttpHost;
|
||||
|
|
@ -18,7 +19,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
|
|||
|
||||
public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
if (allArguments[0] == null || allArguments[1] == null) {
|
||||
// illegal args, can't trace. ignore.
|
||||
|
|
@ -44,7 +45,7 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
|||
httpRequest.setHeader(Config.Plugin.Propagation.HEADER_NAME, contextCarrier.serialize());
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
if (allArguments[0] == null || allArguments[1] == null) {
|
||||
return ret;
|
||||
|
|
@ -62,7 +63,7 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
activeSpan.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ public class HttpClientExecuteInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testHttpClient() throws Throwable {
|
||||
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentsType, null);
|
||||
httpClientExecuteInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentsType, httpResponse);
|
||||
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
httpClientExecuteInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
|
||||
|
||||
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -115,8 +115,8 @@ public class HttpClientExecuteInterceptorTest {
|
|||
@Test
|
||||
public void testStatusCodeNotEquals200() throws Throwable {
|
||||
when(statusLine.getStatusCode()).thenReturn(500);
|
||||
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentsType, null);
|
||||
httpClientExecuteInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentsType, httpResponse);
|
||||
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
httpClientExecuteInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
|
||||
|
||||
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -135,9 +135,9 @@ public class HttpClientExecuteInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testHttpClientWithException() throws Throwable {
|
||||
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentsType, null);
|
||||
httpClientExecuteInterceptor.handleMethodException(enhancedInstance, "execute", allArguments, argumentsType, new RuntimeException("testException"));
|
||||
httpClientExecuteInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentsType, httpResponse);
|
||||
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
httpClientExecuteInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentsType, new RuntimeException("testException"));
|
||||
httpClientExecuteInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
|
||||
|
||||
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.plugin.jdbc.define;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -15,18 +16,18 @@ import org.skywalking.apm.plugin.jdbc.SWConnection;
|
|||
*/
|
||||
public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
return new SWConnection((String)allArguments[0],
|
||||
(Properties)allArguments[1], (Connection)ret);
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.plugin.jedis.v2;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.context.tag.Tags;
|
||||
|
|
@ -12,26 +13,26 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
|
|||
|
||||
public class JedisMethodInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
String peer = String.valueOf(objInst.getSkyWalkingDynamicField());
|
||||
AbstractSpan span = ContextManager.createExitSpan("Jedis/" + methodName, new ContextCarrier(), peer);
|
||||
AbstractSpan span = ContextManager.createExitSpan("Jedis/" + method.getName(), new ContextCarrier(), peer);
|
||||
span.setComponent(ComponentsDefine.REDIS);
|
||||
Tags.DB_TYPE.set(span, "Redis");
|
||||
SpanLayer.asDB(span);
|
||||
|
||||
if (allArguments.length > 0 && allArguments[0] instanceof String) {
|
||||
Tags.DB_STATEMENT.set(span, methodName + " " + allArguments[0]);
|
||||
Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
ContextManager.stopSpan();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.plugin.jedis.v2;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Assert;
|
||||
|
|
@ -8,6 +9,7 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
|
||||
|
|
@ -22,6 +24,7 @@ import org.skywalking.apm.agent.test.tools.AgentServiceRule;
|
|||
import org.skywalking.apm.agent.test.tools.SegmentStorage;
|
||||
import org.skywalking.apm.agent.test.tools.SegmentStoragePoint;
|
||||
import org.skywalking.apm.agent.test.tools.TracingSegmentRunner;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
|
@ -58,8 +61,8 @@ public class JedisMethodInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testIntercept() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "set", allArgument, argumentType, null);
|
||||
interceptor.afterMethod(enhancedInstance, "set", allArgument, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
|
||||
interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null);
|
||||
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||
|
|
@ -71,8 +74,8 @@ public class JedisMethodInterceptorTest {
|
|||
public void testInterceptWithMultiHost() throws Throwable {
|
||||
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:6379;127.0.0.1:16379;");
|
||||
|
||||
interceptor.beforeMethod(enhancedInstance, "set", allArgument, argumentType, null);
|
||||
interceptor.afterMethod(enhancedInstance, "set", allArgument, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
|
||||
interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
|
||||
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||
|
|
@ -82,9 +85,9 @@ public class JedisMethodInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testInterceptWithException() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "set", allArgument, argumentType, null);
|
||||
interceptor.handleMethodException(enhancedInstance, "set", allArgument, argumentType, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, "set", allArgument, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
|
||||
interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
|
||||
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||
|
|
@ -114,4 +117,22 @@ public class JedisMethodInterceptorTest {
|
|||
assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB));
|
||||
}
|
||||
|
||||
private Method getMockSetMethod() {
|
||||
try {
|
||||
return Jedis.class.getMethod("set", String.class, String.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Method getMockGetMethod() {
|
||||
try {
|
||||
return Jedis.class.getMethod("get", String.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import com.mongodb.operation.MixedBulkWriteOperation;
|
|||
import com.mongodb.operation.ReadOperation;
|
||||
import com.mongodb.operation.UpdateOperation;
|
||||
import com.mongodb.operation.WriteOperation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import org.bson.BsonDocument;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
|
|
@ -52,7 +53,7 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
|
|||
|
||||
private static final String DB_TYPE = "MongoDB";
|
||||
|
||||
private static final String METHOD = "MongoDB/";
|
||||
private static final String MONGO_DB_OP_PREFIX = "MongoDB/";
|
||||
|
||||
private static final int FILTER_LENGTH_LIMIT = 256;
|
||||
|
||||
|
|
@ -147,13 +148,13 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Object[] arguments = allArguments;
|
||||
|
||||
String executeMethod = arguments[0].getClass().getSimpleName();
|
||||
String remotePeer = (String)objInst.getSkyWalkingDynamicField();
|
||||
AbstractSpan span = ContextManager.createExitSpan(METHOD + methodName, new ContextCarrier(), remotePeer);
|
||||
AbstractSpan span = ContextManager.createExitSpan(MONGO_DB_OP_PREFIX + method.getName(), new ContextCarrier(), remotePeer);
|
||||
span.setComponent(ComponentsDefine.MONGODB);
|
||||
Tags.DB_TYPE.set(span, DB_TYPE);
|
||||
SpanLayer.asDB(span);
|
||||
|
|
@ -164,13 +165,13 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
|
|||
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
ContextManager.stopSpan();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
activeSpan.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
package org.skywalking.apm.plugin.mongodb.v3;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoNamespace;
|
||||
import com.mongodb.operation.FindOperation;
|
||||
import com.mongodb.operation.WriteOperation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.BsonString;
|
||||
import org.bson.codecs.Decoder;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -78,8 +79,8 @@ public class MongoDBMethodInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testIntercept() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "FindOperation", arguments, argumentTypes, null);
|
||||
interceptor.afterMethod(enhancedInstance, "FindOperation", arguments, argumentTypes, null);
|
||||
interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null);
|
||||
interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -89,9 +90,9 @@ public class MongoDBMethodInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testInterceptWithException() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "FindOperation", arguments, argumentTypes, null);
|
||||
interceptor.handleMethodException(enhancedInstance, "FindOperation", arguments, argumentTypes, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, "FindOperation", arguments, argumentTypes, null);
|
||||
interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null);
|
||||
interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -103,7 +104,7 @@ public class MongoDBMethodInterceptorTest {
|
|||
}
|
||||
|
||||
private void assertRedisSpan(AbstractTracingSpan span) {
|
||||
assertThat(span.getOperationName(), is("MongoDB/FindOperation"));
|
||||
assertThat(span.getOperationName(), is("MongoDB/getUsedDatabases"));
|
||||
assertThat(SpanHelper.getComponentId(span), is(9));
|
||||
List<KeyValuePair> tags = SpanHelper.getTags(span);
|
||||
assertThat(tags.get(1).getValue(), is("FindOperation { \"name\" : \"by\" }"));
|
||||
|
|
@ -112,4 +113,13 @@ public class MongoDBMethodInterceptorTest {
|
|||
assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB));
|
||||
}
|
||||
|
||||
private Method getExecuteMethod(){
|
||||
try {
|
||||
return Mongo.class.getMethod("getUsedDatabases");
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.skywalking.apm.plugin.motan;
|
|||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.Response;
|
||||
import com.weibo.api.motan.rpc.URL;
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -29,7 +30,7 @@ public class MotanConsumerInterceptor implements InstanceConstructorInterceptor,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
URL url = (URL)objInst.getSkyWalkingDynamicField();
|
||||
|
|
@ -45,7 +46,7 @@ public class MotanConsumerInterceptor implements InstanceConstructorInterceptor,
|
|||
}
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Response response = (Response)ret;
|
||||
if (response != null && response.getException() != null) {
|
||||
|
|
@ -57,7 +58,7 @@ public class MotanConsumerInterceptor implements InstanceConstructorInterceptor,
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.skywalking.apm.plugin.motan;
|
|||
|
||||
import com.weibo.api.motan.rpc.Request;
|
||||
import com.weibo.api.motan.rpc.Response;
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -23,7 +24,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
|
|||
*/
|
||||
public class MotanProviderInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Request request = (Request)allArguments[0];
|
||||
String serializedContextData = request.getAttachments().get(Config.Plugin.Propagation.HEADER_NAME);
|
||||
|
|
@ -33,7 +34,7 @@ public class MotanProviderInterceptor implements InstanceMethodsAroundIntercepto
|
|||
span.setComponent(ComponentsDefine.MOTAN);
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Response response = (Response)ret;
|
||||
if (response != null && response.getException() != null) {
|
||||
|
|
@ -46,7 +47,7 @@ public class MotanProviderInterceptor implements InstanceMethodsAroundIntercepto
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
activeSpan.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ public class MotanConsumerInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testInvokeInterceptor() throws Throwable {
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -84,8 +84,8 @@ public class MotanConsumerInterceptorTest {
|
|||
public void testResponseWithException() throws Throwable {
|
||||
when(response.getException()).thenReturn(new RuntimeException());
|
||||
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -104,9 +104,9 @@ public class MotanConsumerInterceptorTest {
|
|||
@Test
|
||||
public void testInvokeInterceptorWithException() throws Throwable {
|
||||
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, null);
|
||||
invokeInterceptor.handleMethodException(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, new RuntimeException());
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", new Object[] {request}, new Class[] {request.getClass()}, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, null);
|
||||
invokeInterceptor.handleMethodException(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, new RuntimeException());
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] {request}, new Class[] {request.getClass()}, response);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ public class MotanProviderInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testInvokerWithoutRefSegment() throws Throwable {
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", arguments, argumentType, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", arguments, argumentType, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -94,8 +94,8 @@ public class MotanProviderInterceptorTest {
|
|||
attachments.put(Config.Plugin.Propagation.HEADER_NAME, "#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
when(request.getAttachments()).thenReturn(attachments);
|
||||
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", arguments, argumentType, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", arguments, argumentType, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response);
|
||||
|
||||
MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -108,8 +108,8 @@ public class MotanProviderInterceptorTest {
|
|||
public void testResponseWithException() throws Throwable {
|
||||
when(response.getException()).thenReturn(new RuntimeException());
|
||||
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", arguments, argumentType, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", arguments, argumentType, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response);
|
||||
|
||||
assertTraceSegmentWhenOccurException();
|
||||
}
|
||||
|
|
@ -117,9 +117,9 @@ public class MotanProviderInterceptorTest {
|
|||
@Test
|
||||
public void testOccurException() throws Throwable {
|
||||
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, "execute", arguments, argumentType, null);
|
||||
invokeInterceptor.handleMethodException(enhancedInstance, "execute", arguments, argumentType, new RuntimeException());
|
||||
invokeInterceptor.afterMethod(enhancedInstance, "execute", arguments, argumentType, response);
|
||||
invokeInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
invokeInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
|
||||
invokeInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, response);
|
||||
|
||||
assertTraceSegmentWhenOccurException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.skywalking.apm.plugin.okhttp.v3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.HttpUrl;
|
||||
|
|
@ -43,10 +44,12 @@ public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, In
|
|||
* port, kind, component, url from {@link okhttp3.Request}.
|
||||
* Through the reflection of the way, set the http header of context data into {@link okhttp3.Request#headers}.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Request request = (Request)objInst.getSkyWalkingDynamicField();
|
||||
|
||||
|
|
@ -73,12 +76,14 @@ public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, In
|
|||
* the server.
|
||||
* Finish the {@link AbstractSpan}.
|
||||
*
|
||||
*
|
||||
* @param method
|
||||
* @param ret the method's original return value.
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Response response = (Response)ret;
|
||||
int statusCode = response.code();
|
||||
|
|
@ -94,7 +99,7 @@ public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, In
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan abstractSpan = ContextManager.activeSpan();
|
||||
abstractSpan.errorOccurred();
|
||||
|
|
|
|||
|
|
@ -93,11 +93,11 @@ public class RealCallInterceptorTest {
|
|||
@Test
|
||||
public void testMethodsAround() throws Throwable {
|
||||
realCallInterceptor.onConstruct(enhancedInstance, allArguments);
|
||||
realCallInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentTypes, null);
|
||||
realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
|
||||
|
||||
Response response = mock(Response.class);
|
||||
when(response.code()).thenReturn(200);
|
||||
realCallInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentTypes, response);
|
||||
realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -110,11 +110,11 @@ public class RealCallInterceptorTest {
|
|||
@Test
|
||||
public void testMethodsAroundError() throws Throwable {
|
||||
realCallInterceptor.onConstruct(enhancedInstance, allArguments);
|
||||
realCallInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentTypes, null);
|
||||
realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
|
||||
|
||||
Response response = mock(Response.class);
|
||||
when(response.code()).thenReturn(404);
|
||||
realCallInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentTypes, response);
|
||||
realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -136,13 +136,13 @@ public class RealCallInterceptorTest {
|
|||
@Test
|
||||
public void testException() throws Throwable {
|
||||
realCallInterceptor.onConstruct(enhancedInstance, allArguments);
|
||||
realCallInterceptor.beforeMethod(enhancedInstance, "execute", allArguments, argumentTypes, null);
|
||||
realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
|
||||
|
||||
realCallInterceptor.handleMethodException(enhancedInstance, "execute", allArguments, argumentTypes, new NullPointerException("testException"));
|
||||
realCallInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException"));
|
||||
|
||||
Response response = mock(Response.class);
|
||||
when(response.code()).thenReturn(200);
|
||||
realCallInterceptor.afterMethod(enhancedInstance, "execute", allArguments, argumentTypes, response);
|
||||
realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.skywalking.apm.plugin.resin.v3;
|
|||
|
||||
import com.caucho.server.connection.CauchoRequest;
|
||||
import com.caucho.server.http.HttpResponse;
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -21,7 +22,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
|
|||
*/
|
||||
public class ResinV3Interceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
CauchoRequest request = (CauchoRequest)allArguments[0];
|
||||
String tracingHeaderValue = request.getHeader(Config.Plugin.Propagation.HEADER_NAME);
|
||||
|
|
@ -32,7 +33,7 @@ public class ResinV3Interceptor implements InstanceMethodsAroundInterceptor {
|
|||
SpanLayer.asHttp(span);
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
HttpResponse response = (HttpResponse)allArguments[1];
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
|
|
@ -46,7 +47,7 @@ public class ResinV3Interceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
activeSpan.log(t);
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ public class ResinV3InterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithoutSerializedContextData() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -92,8 +92,8 @@ public class ResinV3InterceptorTest {
|
|||
public void testWithSerializedContextData() throws Throwable {
|
||||
when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -105,9 +105,9 @@ public class ResinV3InterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithOccurException() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
|
||||
interceptor.handleMethodException(enhancedInstance, "service", arguments, argumentType, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.skywalking.apm.plugin.resin.v4;
|
||||
|
||||
import com.caucho.server.http.CauchoRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
|
|
@ -18,7 +19,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
|
|||
*/
|
||||
public class ResinV4Interceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
CauchoRequest request = (CauchoRequest)allArguments[0];
|
||||
String tracingHeaderValue = request.getHeader(Config.Plugin.Propagation.HEADER_NAME);
|
||||
|
|
@ -31,7 +32,7 @@ public class ResinV4Interceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
HttpServletResponse response = (HttpServletResponse)allArguments[1];
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
|
|
@ -44,7 +45,7 @@ public class ResinV4Interceptor implements InstanceMethodsAroundInterceptor {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
activeSpan.log(t);
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ public class ResinV4InterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithoutSerializedContextData() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -94,8 +94,8 @@ public class ResinV4InterceptorTest {
|
|||
public void testWithSerializedContextData() throws Throwable {
|
||||
when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -107,9 +107,9 @@ public class ResinV4InterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithOccurException() throws Throwable {
|
||||
interceptor.beforeMethod(enhancedInstance, "service", arguments, argumentType, methodInterceptResult);
|
||||
interceptor.handleMethodException(enhancedInstance, "service", arguments, argumentType, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, "service", arguments, argumentType, null);
|
||||
interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
|
||||
interceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.plugin.tomcat78x;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
|
|
@ -26,13 +27,13 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
* trace segment id of the previous level if the serialized context is not null.
|
||||
*
|
||||
* @param objInst
|
||||
* @param methodName
|
||||
* @param method
|
||||
* @param allArguments
|
||||
* @param argumentsTypes
|
||||
* @param result change this result, if you want to truncate the method.
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
HttpServletRequest request = (HttpServletRequest)allArguments[0];
|
||||
String tracingHeaderValue = request.getHeader(Config.Plugin.Propagation.HEADER_NAME);
|
||||
|
|
@ -45,7 +46,7 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
HttpServletResponse response = (HttpServletResponse)allArguments[1];
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.log(t);
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ public class TomcatInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithoutSerializedContextData() throws Throwable {
|
||||
tomcatInterceptor.beforeMethod(enhancedInstance, "invoke", arguments, argumentType, methodInterceptResult);
|
||||
tomcatInterceptor.afterMethod(enhancedInstance, "invoke", arguments, argumentType, null);
|
||||
tomcatInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
tomcatInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -84,8 +84,8 @@ public class TomcatInterceptorTest {
|
|||
public void testWithSerializedContextData() throws Throwable {
|
||||
when(request.getHeader(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
tomcatInterceptor.beforeMethod(enhancedInstance, "invoke", arguments, argumentType, methodInterceptResult);
|
||||
tomcatInterceptor.afterMethod(enhancedInstance, "invoke", arguments, argumentType, null);
|
||||
tomcatInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
tomcatInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
@ -97,9 +97,9 @@ public class TomcatInterceptorTest {
|
|||
|
||||
@Test
|
||||
public void testWithOccurException() throws Throwable {
|
||||
tomcatInterceptor.beforeMethod(enhancedInstance, "invoke", arguments, argumentType, methodInterceptResult);
|
||||
tomcatInterceptor.handleMethodException(enhancedInstance, "invoke", arguments, argumentType, new RuntimeException());
|
||||
tomcatInterceptor.afterMethod(enhancedInstance, "invoke", arguments, argumentType, null);
|
||||
tomcatInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
|
||||
tomcatInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
|
||||
tomcatInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.log.log4j.v1.x;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
|
|
@ -10,17 +11,17 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
*/
|
||||
public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
return "TID:" + ContextManager.getGlobalTraceId();
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.log.log4j.v2.x;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
|
||||
|
|
@ -11,9 +12,10 @@ public class PrintTraceIdInterceptor implements StaticMethodsAroundInterceptor {
|
|||
/**
|
||||
* Override org.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender.append(),
|
||||
*
|
||||
* @param method
|
||||
* @param result change this result, to output the traceId. The origin append() method will not invoke.
|
||||
*/
|
||||
@Override public void beforeMethod(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
@Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
MethodInterceptResult result) {
|
||||
((StringBuilder)allArguments[0]).append("TID:" + ContextManager.getGlobalTraceId());
|
||||
|
||||
|
|
@ -22,13 +24,13 @@ public class PrintTraceIdInterceptor implements StaticMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Object ret) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.log.logback.v1.x;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
|
|
@ -10,17 +11,17 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
*/
|
||||
public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
return "TID:" + ContextManager.getGlobalTraceId();
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.continuation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.context.ContextSnapshot;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -7,11 +8,11 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsA
|
|||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
public class ActivateInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
}
|
||||
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Object contextSnapshot = objInst.getSkyWalkingDynamicField();
|
||||
if (contextSnapshot != null) {
|
||||
|
|
@ -20,7 +21,7 @@ public class ActivateInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.span;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -8,13 +9,13 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
|
||||
public class SpanFinishInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
AbstractSpan abstractSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField();
|
||||
if (abstractSpan != null) {
|
||||
|
|
@ -24,7 +25,7 @@ public class SpanFinishInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.span;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -11,13 +12,13 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
*/
|
||||
public class SpanLogInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
AbstractSpan abstractSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField();
|
||||
if (abstractSpan != null) {
|
||||
|
|
@ -27,7 +28,7 @@ public class SpanLogInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.span;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
|
|
@ -7,13 +8,13 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
|
||||
public class SpanSetOperationNameInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
AbstractSpan tracingSpan = (AbstractSpan)objInst.getSkyWalkingDynamicField();
|
||||
if (tracingSpan != null) {
|
||||
|
|
@ -23,7 +24,7 @@ public class SpanSetOperationNameInterceptor implements InstanceMethodsAroundInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.span;
|
||||
|
||||
import io.opentracing.tag.Tags;
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -9,12 +10,12 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
|
||||
public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
AbstractSpan activeSpan = ContextManager.activeSpan();
|
||||
String tagKey = String.valueOf(allArguments[0]);
|
||||
|
|
@ -30,7 +31,7 @@ public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.tracer;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -8,13 +9,13 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
|
||||
public class SkywalkingTracerExtractInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
String carrier = (String)allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize(carrier);
|
||||
|
|
@ -23,7 +24,7 @@ public class SkywalkingTracerExtractInterceptor implements InstanceMethodsAround
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.tracer;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -8,13 +9,13 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
|
|||
|
||||
public class SkywalkingTracerInjectInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
ContextManager.inject(contextCarrier);
|
||||
|
|
@ -22,7 +23,7 @@ public class SkywalkingTracerInjectInterceptor implements InstanceMethodsAroundI
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, String methodName, Object[] allArguments,
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import io.opentracing.Tracer;
|
|||
import io.opentracing.tag.Tags;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -30,7 +31,10 @@ import org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor
|
|||
import org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor;
|
||||
import org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor;
|
||||
import org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor;
|
||||
import org.skywalking.apm.toolkit.opentracing.SkywalkingContinuation;
|
||||
import org.skywalking.apm.toolkit.opentracing.SkywalkingSpan;
|
||||
import org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder;
|
||||
import org.skywalking.apm.toolkit.opentracing.SkywalkingTracer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
|
@ -166,7 +170,7 @@ public class SkywalkingSpanActivationTest {
|
|||
.withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
|
||||
startSpan();
|
||||
|
||||
String extractValue = (String)injectInterceptor.afterMethod(enhancedInstance, "extract",
|
||||
String extractValue = (String)injectInterceptor.afterMethod(enhancedInstance, null,
|
||||
null, null, null);
|
||||
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize(extractValue);
|
||||
|
|
@ -182,7 +186,7 @@ public class SkywalkingSpanActivationTest {
|
|||
spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
|
||||
.withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
|
||||
startSpan();
|
||||
extractInterceptor.afterMethod(enhancedInstance, "extract",
|
||||
extractInterceptor.afterMethod(enhancedInstance, null,
|
||||
new Object[] {"#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"}, new Class[] {String.class}, null);
|
||||
stopSpan();
|
||||
|
||||
|
|
@ -197,12 +201,13 @@ public class SkywalkingSpanActivationTest {
|
|||
assertThat(spans.size(), is(1));
|
||||
assertSpanCommonsAttribute(spans.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractWithInValidateContext() throws Throwable {
|
||||
spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
|
||||
.withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
|
||||
startSpan();
|
||||
extractInterceptor.afterMethod(enhancedInstance, "extract",
|
||||
extractInterceptor.afterMethod(enhancedInstance, null,
|
||||
new Object[] {"#AQA*#AQA*4WcWe0tQNQA*|3|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"}, new Class[] {String.class}, null);
|
||||
stopSpan();
|
||||
|
||||
|
|
@ -223,7 +228,7 @@ public class SkywalkingSpanActivationTest {
|
|||
MockEnhancedInstance enhancedInstance = new MockEnhancedInstance();
|
||||
try {
|
||||
startSpan(enhancedInstance);
|
||||
activateInterceptor.afterMethod(continuationHolder, "activate", null, null, null);
|
||||
activateInterceptor.afterMethod(continuationHolder, SkywalkingContinuation.class.getMethod("activate"), null, null, null);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
} finally {
|
||||
|
|
@ -258,7 +263,7 @@ public class SkywalkingSpanActivationTest {
|
|||
}
|
||||
|
||||
private void stopSpan(EnhancedInstance enhancedInstance) throws Throwable {
|
||||
spanFinishInterceptor.afterMethod(enhancedInstance, "finish", null, null, null);
|
||||
spanFinishInterceptor.afterMethod(enhancedInstance, null, null, null, null);
|
||||
}
|
||||
|
||||
private void startSpan() throws Throwable {
|
||||
|
|
@ -267,9 +272,9 @@ public class SkywalkingSpanActivationTest {
|
|||
|
||||
private void startSpan(MockEnhancedInstance enhancedInstance) throws Throwable {
|
||||
constructorWithSpanBuilderInterceptor.onConstruct(enhancedInstance, new Object[] {spanBuilder});
|
||||
spanLogInterceptor.afterMethod(enhancedInstance, "log", logArgument, logArgumentType, null);
|
||||
spanLogInterceptor.afterMethod(enhancedInstance, null, logArgument, logArgumentType, null);
|
||||
|
||||
setOperationNameInterceptor.afterMethod(enhancedInstance, "setOperationName",
|
||||
setOperationNameInterceptor.afterMethod(enhancedInstance, SkywalkingSpan.class.getMethod("setOperationName", String.class),
|
||||
setOperationNameArgument, setOperationNameArgumentType, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.activation.trace;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
|
||||
|
|
@ -10,19 +11,19 @@ public class TraceContextInterceptor implements StaticMethodsAroundInterceptor {
|
|||
|
||||
private ILog logger = LogManager.getLogger(TraceContextInterceptor.class);
|
||||
|
||||
@Override public void beforeMethod(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
@Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
MethodInterceptResult result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Object ret) {
|
||||
return ContextManager.getGlobalTraceId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Class clazz, String methodName, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Throwable t) {
|
||||
logger.error("Failed to get trace Id.", t);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue