Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
javalover123888
SkyWalking
提交
ba1254b7
S
SkyWalking
项目概览
javalover123888
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ba1254b7
编写于
8月 10, 2017
作者:
wu-sheng
提交者:
GitHub
8月 10, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into feature/346
上级
b9404f6a
72003d71
变更
44
隐藏空白更改
内联
并排
Showing
44 changed file
with
271 addition
and
190 deletion
+271
-190
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
...m/agent/core/plugin/AbstractClassEnhancePluginDefine.java
+2
-2
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java
...va/org/skywalking/apm/agent/core/plugin/PluginFinder.java
+1
-1
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java
...alking/apm/agent/core/plugin/PluginResourcesResolver.java
+2
-2
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java
...ent/core/plugin/interceptor/enhance/InstMethodsInter.java
+3
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java
...interceptor/enhance/InstMethodsInterWithOverrideArgs.java
+3
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java
...interceptor/enhance/InstanceMethodsAroundInterceptor.java
+10
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java
...n/interceptor/enhance/StaticMethodsAroundInterceptor.java
+9
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java
...t/core/plugin/interceptor/enhance/StaticMethodsInter.java
+3
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java
...terceptor/enhance/StaticMethodsInterWithOverrideArgs.java
+3
-3
apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInterceptor.java
...ava/org/skywalking/apm/plugin/dubbo/DubboInterceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java
...org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java
+13
-13
apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java
...pm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java
+8
-3
apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java
...lugin/feign/http/v9/DefaultHttpClientInterceptorTest.java
+7
-7
apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java
...pm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java
...lugin/httpClient/v4/HttpClientExecuteInterceptorTest.java
+7
-7
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/JDBCDriverInterceptor.java
...walking/apm/plugin/jdbc/define/JDBCDriverInterceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java
...kywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java
+6
-5
apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java
...lking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java
+28
-7
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java
...lking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java
+6
-5
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java
...g/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java
+18
-8
apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java
...skywalking/apm/plugin/motan/MotanConsumerInterceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptor.java
...skywalking/apm/plugin/motan/MotanProviderInterceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java
...alking/apm/plugin/motan/MotanConsumerInterceptorTest.java
+7
-7
apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java
...alking/apm/plugin/motan/MotanProviderInterceptorTest.java
+9
-9
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
.../skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
+8
-3
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
...walking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
+7
-7
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java
...rg/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java
...kywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java
+7
-7
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java
...rg/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java
+4
-3
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java
...kywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java
+7
-7
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptor.java
...rg/skywalking/apm/plugin/tomcat78x/TomcatInterceptor.java
+5
-4
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java
...kywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java
+7
-7
apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java
...it/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java
...it/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java
+5
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java
.../activation/log/logback/v1/x/PrintTraceIdInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java
...ivation/opentracing/continuation/ActivateInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java
...it/activation/opentracing/span/SpanFinishInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java
...olkit/activation/opentracing/span/SpanLogInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java
...ion/opentracing/span/SpanSetOperationNameInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java
...it/activation/opentracing/span/SpanSetTagInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java
...pentracing/tracer/SkywalkingTracerExtractInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java
...opentracing/tracer/SkywalkingTracerInjectInterceptor.java
+4
-3
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
.../activation/opentracing/SkywalkingSpanActivationTest.java
+12
-7
apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-context-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java
...apm/toolkit/activation/trace/TraceContextInterceptor.java
+4
-3
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
浏览文件 @
ba1254b7
...
...
@@ -37,7 +37,7 @@ public abstract class AbstractClassEnhancePluginDefine {
logger
.
debug
(
"prepare to enhance class {} by {}."
,
transformClassName
,
interceptorDefineClassName
);
/**
* find
OrPrepare4Register
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 {
}
/**
* find
OrPrepare4Register
origin class source code for interceptor
* find origin class source code for interceptor
*/
DynamicType
.
Builder
<?>
newClassBuilder
=
this
.
enhance
(
transformClassName
,
builder
,
classLoader
);
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java
浏览文件 @
ba1254b7
...
...
@@ -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 find
OrPrepare4Register
the one
* The <code>PluginFinder</code> represents a finder , which assist to find the one
* from the given {@link AbstractClassEnhancePluginDefine} list.
*
* @author wusheng
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java
浏览文件 @
ba1254b7
...
...
@@ -27,7 +27,7 @@ public class PluginResourcesResolver {
while
(
urls
.
hasMoreElements
())
{
URL
pluginUrl
=
urls
.
nextElement
();
cfgUrlPaths
.
add
(
pluginUrl
);
logger
.
info
(
"find
OrPrepare4Register
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 find
OrPrepare4Register
plugin definitions.
* @return the classloader to find plugin definitions.
*/
private
ClassLoader
getDefaultClassLoader
()
{
ClassLoader
cl
=
null
;
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInter.java
浏览文件 @
ba1254b7
...
...
@@ -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
());
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java
浏览文件 @
ba1254b7
...
...
@@ -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
());
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java
浏览文件 @
ba1254b7
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
);
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java
浏览文件 @
ba1254b7
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
);
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java
浏览文件 @
ba1254b7
...
...
@@ -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
());
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java
浏览文件 @
ba1254b7
...
...
@@ -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
());
}
...
...
apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/main/java/org/skywalking/apm/plugin/dubbo/DubboInterceptor.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
}
...
...
apm-sniffer/apm-sdk-plugin/dubbo-plugin/src/test/java/org/skywalking/apm/plugin/dubbo/DubboInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
();
}
...
...
apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/main/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptor.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/feign-default-http-9.x-plugin/src/test/java/org/skywalking/apm/plugin/feign/http/v9/DefaultHttpClientInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java
浏览文件 @
ba1254b7
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
();
...
...
apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/JDBCDriverInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptor.java
浏览文件 @
ba1254b7
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/"
+
method
Name
,
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
,
method
Name
+
" "
+
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
();
...
...
apm-sniffer/apm-sdk-plugin/jedis-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jedis/v2/JedisMethodInterceptorTest.java
浏览文件 @
ba1254b7
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
;
}
}
}
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java
浏览文件 @
ba1254b7
...
...
@@ -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
M
ETHOD
=
"MongoDB/"
;
private
static
final
String
M
ONGO_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
(
M
ETHOD
+
methodName
,
new
ContextCarrier
(),
remotePeer
);
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
M
ONGO_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
();
...
...
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java
浏览文件 @
ba1254b7
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
;
}
}
}
apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptor.java
浏览文件 @
ba1254b7
...
...
@@ -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
();
...
...
apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptor.java
浏览文件 @
ba1254b7
...
...
@@ -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
();
...
...
apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanConsumerInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/motan-plugin/src/test/java/org/skywalking/apm/plugin/motan/MotanProviderInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
();
}
...
...
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
浏览文件 @
ba1254b7
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
();
...
...
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java
浏览文件 @
ba1254b7
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
);
...
...
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptor.java
浏览文件 @
ba1254b7
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 method
Name
* @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
);
...
...
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/skywalking/apm/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetTagInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java
浏览文件 @
ba1254b7
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
)
{
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
浏览文件 @
ba1254b7
...
...
@@ -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
);
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-context-activation/src/main/java/org/skywalking/apm/toolkit/activation/trace/TraceContextInterceptor.java
浏览文件 @
ba1254b7
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
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录