Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
javalover123888
SkyWalking
提交
fa2fdb4e
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,发现更多精彩内容 >>
提交
fa2fdb4e
编写于
8月 12, 2016
作者:
A
ascrutae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成自定义拦截插件
上级
e52c50c0
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
209 addition
and
43 deletion
+209
-43
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java
...pi/src/main/java/com/ai/cloud/skywalking/conf/Config.java
+6
-0
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/model/Identification.java
...in/java/com/ai/cloud/skywalking/model/Identification.java
+0
-5
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/enhance/ClassStaticMethodsInterceptor.java
...in/interceptor/enhance/ClassStaticMethodsInterceptor.java
+1
-1
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/enhance/InstanceMethodInvokeContext.java
...ugin/interceptor/enhance/InstanceMethodInvokeContext.java
+13
-13
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/enhance/MethodInvokeContext.java
...lking/plugin/interceptor/enhance/MethodInvokeContext.java
+36
-23
skywalking-collector/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/ai/cloud/skywalking/jedis/v2/plugin/define/JedisClusterPluginDefine.java
...king/jedis/v2/plugin/define/JedisClusterPluginDefine.java
+0
-1
skywalking-collector/skywalking-sdk-plugin/pom.xml
skywalking-collector/skywalking-sdk-plugin/pom.xml
+1
-0
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/pom.xml
...walking-sdk-plugin/self-define-interceptor-plugin/pom.xml
+19
-0
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/java/com/ai/cloud/skywalking/self/define/plugin/SelfDefineMethodInterceptor.java
...lking/self/define/plugin/SelfDefineMethodInterceptor.java
+69
-0
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/java/com/ai/cloud/skywalking/self/define/plugin/SelfDefineSpanType.java
...oud/skywalking/self/define/plugin/SelfDefineSpanType.java
+16
-0
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/java/com/ai/cloud/skywalking/self/define/plugin/define/SelfDefineMethodPluginDefine.java
...lf/define/plugin/define/SelfDefineMethodPluginDefine.java
+47
-0
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/resources/skywalking-plugin.def
...terceptor-plugin/src/main/resources/skywalking-plugin.def
+1
-0
未找到文件。
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java
浏览文件 @
fa2fdb4e
...
@@ -18,6 +18,12 @@ public class Config {
...
@@ -18,6 +18,12 @@ public class Config {
public
static
boolean
IS_PREMAIN_MODE
=
false
;
public
static
boolean
IS_PREMAIN_MODE
=
false
;
public
static
String
AGENT_BASE_PATH
=
""
;
public
static
String
AGENT_BASE_PATH
=
""
;
public
static
boolean
SELF_DEFINE_METHOD_INTERCEPTOR
=
false
;
public
static
String
SELF_DEFINE_METHOD_PACKAGE
=
""
;
public
static
boolean
RECORD_PARAM
=
false
;
}
}
...
...
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/model/Identification.java
浏览文件 @
fa2fdb4e
...
@@ -60,11 +60,6 @@ public class Identification {
...
@@ -60,11 +60,6 @@ public class Identification {
return
this
;
return
this
;
}
}
public
IdentificationBuilder
setParameter
(
String
key
,
String
value
)
{
sendData
.
parameters
.
put
(
key
,
value
);
return
this
;
}
public
IdentificationBuilder
addParameter
(
String
value
){
public
IdentificationBuilder
addParameter
(
String
value
){
parameterIdx
++;
parameterIdx
++;
sendData
.
parameters
.
put
(
"_"
+
parameterIdx
,
value
);
sendData
.
parameters
.
put
(
"_"
+
parameterIdx
,
value
);
...
...
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/enhance/ClassStaticMethodsInterceptor.java
浏览文件 @
fa2fdb4e
...
@@ -29,7 +29,7 @@ public class ClassStaticMethodsInterceptor {
...
@@ -29,7 +29,7 @@ public class ClassStaticMethodsInterceptor {
public
Object
intercept
(
@Origin
Class
<?>
clazz
,
@AllArguments
Object
[]
allArguments
,
@Origin
Method
method
,
@SuperCall
Callable
<?>
zuper
)
throws
Exception
{
public
Object
intercept
(
@Origin
Class
<?>
clazz
,
@AllArguments
Object
[]
allArguments
,
@Origin
Method
method
,
@SuperCall
Callable
<?>
zuper
)
throws
Exception
{
StaticMethodsAroundInterceptor
interceptor
=
InterceptorInstanceLoader
.
load
(
staticMethodsAroundInterceptorClassName
,
clazz
.
getClassLoader
());
StaticMethodsAroundInterceptor
interceptor
=
InterceptorInstanceLoader
.
load
(
staticMethodsAroundInterceptorClassName
,
clazz
.
getClassLoader
());
MethodInvokeContext
interceptorContext
=
new
MethodInvokeContext
(
method
.
getName
(),
allArguments
);
MethodInvokeContext
interceptorContext
=
new
MethodInvokeContext
(
clazz
,
method
.
getName
(),
allArguments
);
MethodInterceptResult
result
=
new
MethodInterceptResult
();
MethodInterceptResult
result
=
new
MethodInterceptResult
();
try
{
try
{
interceptor
.
beforeMethod
(
interceptorContext
,
result
);
interceptor
.
beforeMethod
(
interceptorContext
,
result
);
...
...
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/enhance/InstanceMethodInvokeContext.java
浏览文件 @
fa2fdb4e
package
com.ai.cloud.skywalking.plugin.interceptor.enhance
;
package
com.ai.cloud.skywalking.plugin.interceptor.enhance
;
public
class
InstanceMethodInvokeContext
extends
MethodInvokeContext
{
public
class
InstanceMethodInvokeContext
extends
MethodInvokeContext
{
/**
/**
* 代理类实例
* 代理类实例
*/
*/
private
Object
objInst
;
private
Object
objInst
;
InstanceMethodInvokeContext
(
Object
objInst
,
String
methodName
,
Object
[]
allArguments
)
{
InstanceMethodInvokeContext
(
Object
objInst
,
String
methodName
,
Object
[]
allArguments
)
{
super
(
methodName
,
allArguments
);
super
(
objInst
.
getClass
(),
methodName
,
allArguments
);
this
.
objInst
=
objInst
;
this
.
objInst
=
objInst
;
}
}
public
Object
inst
()
{
public
Object
inst
()
{
return
objInst
;
return
objInst
;
}
}
}
}
skywalking-collector/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/enhance/MethodInvokeContext.java
浏览文件 @
fa2fdb4e
...
@@ -2,30 +2,43 @@ package com.ai.cloud.skywalking.plugin.interceptor.enhance;
...
@@ -2,30 +2,43 @@ package com.ai.cloud.skywalking.plugin.interceptor.enhance;
/**
/**
* 方法执行拦截上下文
* 方法执行拦截上下文
*
* @author wusheng
*
*
* @author wusheng
*/
*/
public
class
MethodInvokeContext
{
public
class
MethodInvokeContext
{
/**
/**
* 方法名称
* 方法名称
*/
*/
private
String
methodName
;
private
String
methodName
;
/**
/**
* 方法参数
* 方法参数
*/
*/
private
Object
[]
allArguments
;
private
Object
[]
allArguments
;
MethodInvokeContext
(
String
methodName
,
Object
[]
allArguments
)
{
MethodInvokeContext
(
Class
clazz
,
String
methodName
,
Object
[]
allArguments
)
{
this
.
methodName
=
methodName
;
this
.
methodName
=
appendMethodName
(
clazz
,
methodName
,
allArguments
);
this
.
allArguments
=
allArguments
;
this
.
allArguments
=
allArguments
;
}
}
public
Object
[]
allArguments
(){
public
Object
[]
allArguments
()
{
return
this
.
allArguments
;
return
this
.
allArguments
;
}
}
public
String
methodName
(){
public
String
methodName
()
{
return
methodName
;
return
methodName
;
}
}
private
String
appendMethodName
(
Class
clazz
,
String
simpleMethodName
,
Object
[]
allArguments
)
{
StringBuilder
methodName
=
new
StringBuilder
(
clazz
.
getName
()
+
"."
+
simpleMethodName
+
"("
);
for
(
Object
argument
:
allArguments
)
{
methodName
.
append
(
argument
.
getClass
()
+
","
);
}
if
(
allArguments
.
length
>
0
){
methodName
.
deleteCharAt
(
methodName
.
length
()
-
1
);
}
methodName
.
append
(
")"
);
return
methodName
.
toString
();
}
}
}
skywalking-collector/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/ai/cloud/skywalking/jedis/v2/plugin/define/JedisClusterPluginDefine.java
浏览文件 @
fa2fdb4e
package
com.ai.cloud.skywalking.jedis.v2.plugin.define
;
package
com.ai.cloud.skywalking.jedis.v2.plugin.define
;
import
com.ai.cloud.skywalking.jedis.v2.plugin.JedisClusterInterceptor
;
import
com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher
;
import
com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher
;
import
com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher
;
import
com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher
;
...
...
skywalking-collector/skywalking-sdk-plugin/pom.xml
浏览文件 @
fa2fdb4e
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
<module>
httpClient-4.x-plugin
</module>
<module>
httpClient-4.x-plugin
</module>
<module>
jedis-2.x-plugin
</module>
<module>
jedis-2.x-plugin
</module>
<module>
tomcat-7.x-8.x-plugin
</module>
<module>
tomcat-7.x-8.x-plugin
</module>
<module>
self-define-interceptor-plugin
</module>
</modules>
</modules>
<packaging>
pom
</packaging>
<packaging>
pom
</packaging>
...
...
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/pom.xml
0 → 100644
浏览文件 @
fa2fdb4e
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
skywalking-sdk-plugin
</artifactId>
<groupId>
com.ai.cloud
</groupId>
<version>
1.0-Final
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
self-define-interceptor-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
self-define-interceptor-plugin
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
</project>
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/java/com/ai/cloud/skywalking/self/define/plugin/SelfDefineMethodInterceptor.java
0 → 100644
浏览文件 @
fa2fdb4e
package
com.ai.cloud.skywalking.self.define.plugin
;
import
com.ai.cloud.skywalking.conf.Config
;
import
com.ai.cloud.skywalking.invoke.monitor.LocalMethodInvokeMonitor
;
import
com.ai.cloud.skywalking.model.Identification
;
import
com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.ai.cloud.skywalking.plugin.interceptor.enhance.*
;
import
com.google.gson.Gson
;
public
class
SelfDefineMethodInterceptor
implements
InstanceMethodsAroundInterceptor
,
StaticMethodsAroundInterceptor
{
@Override
public
void
onConstruct
(
EnhancedClassInstanceContext
context
,
ConstructorInvokeContext
interceptorContext
)
{
}
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
Identification
.
IdentificationBuilder
identificationBuilder
=
buildIdentificationBuilder
(
interceptorContext
);
new
LocalMethodInvokeMonitor
().
beforeInvoke
(
identificationBuilder
.
build
());
}
private
Identification
.
IdentificationBuilder
buildIdentificationBuilder
(
MethodInvokeContext
interceptorContext
)
{
Identification
.
IdentificationBuilder
identificationBuilder
=
Identification
.
newBuilder
();
if
(
Config
.
SkyWalking
.
RECORD_PARAM
)
{
for
(
Object
param
:
interceptorContext
.
allArguments
())
{
String
paramStr
;
try
{
paramStr
=
new
Gson
().
toJson
(
param
);
}
catch
(
Exception
e
)
{
paramStr
=
"N/A"
;
}
identificationBuilder
.
addParameter
(
paramStr
);
}
}
identificationBuilder
.
spanType
(
new
SelfDefineSpanType
()).
viewPoint
(
interceptorContext
.
methodName
());
return
identificationBuilder
;
}
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
new
LocalMethodInvokeMonitor
().
afterInvoke
();
return
ret
;
}
@Override
public
void
handleMethodException
(
Throwable
t
,
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
)
{
new
LocalMethodInvokeMonitor
().
occurException
(
t
);
}
@Override
public
void
beforeMethod
(
MethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
new
LocalMethodInvokeMonitor
().
beforeInvoke
(
buildIdentificationBuilder
(
interceptorContext
).
build
());
}
@Override
public
Object
afterMethod
(
MethodInvokeContext
interceptorContext
,
Object
ret
)
{
new
LocalMethodInvokeMonitor
().
afterInvoke
();
return
ret
;
}
@Override
public
void
handleMethodException
(
Throwable
t
,
MethodInvokeContext
interceptorContext
)
{
new
LocalMethodInvokeMonitor
().
occurException
(
t
);
}
}
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/java/com/ai/cloud/skywalking/self/define/plugin/SelfDefineSpanType.java
0 → 100644
浏览文件 @
fa2fdb4e
package
com.ai.cloud.skywalking.self.define.plugin
;
import
com.ai.cloud.skywalking.api.IBuriedPointType
;
import
com.ai.cloud.skywalking.protocol.common.CallType
;
public
class
SelfDefineSpanType
implements
IBuriedPointType
{
@Override
public
String
getTypeName
()
{
return
"L"
;
}
@Override
public
CallType
getCallType
()
{
return
CallType
.
SYNC
;
}
}
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/java/com/ai/cloud/skywalking/self/define/plugin/define/SelfDefineMethodPluginDefine.java
0 → 100644
浏览文件 @
fa2fdb4e
package
com.ai.cloud.skywalking.self.define.plugin.define
;
import
com.ai.cloud.skywalking.conf.Config
;
import
com.ai.cloud.skywalking.plugin.PluginException
;
import
com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher
;
import
com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine
;
import
com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher
;
import
net.bytebuddy.dynamic.DynamicType
;
public
class
SelfDefineMethodPluginDefine
extends
ClassEnhancePluginDefine
{
@Override
protected
DynamicType
.
Builder
<?>
enhance
(
String
enhanceOriginClassName
,
DynamicType
.
Builder
<?>
newClassBuilder
)
throws
PluginException
{
return
Config
.
SkyWalking
.
SELF_DEFINE_METHOD_INTERCEPTOR
?
super
.
enhance
(
enhanceOriginClassName
,
newClassBuilder
)
:
newClassBuilder
;
}
@Override
protected
MethodMatcher
[]
getInstanceMethodsMatchers
()
{
return
new
MethodMatcher
[]
{
new
AnyMethodsMatcher
()};
}
@Override
protected
String
getInstanceMethodsInterceptor
()
{
return
"com.ai.cloud.skywalking.self.define.plugin.SelfDefineMethodInterceptor"
;
}
@Override
protected
MethodMatcher
[]
getStaticMethodsMatchers
()
{
return
new
MethodMatcher
[]
{
new
AnyMethodsMatcher
()};
}
@Override
protected
String
getStaticMethodsInterceptor
()
{
return
"com.ai.cloud.skywalking.self.define.plugin.SelfDefineMethodInterceptor"
;
}
@Override
protected
String
enhanceClassName
()
{
if
(!
Config
.
SkyWalking
.
SELF_DEFINE_METHOD_PACKAGE
.
endsWith
(
".*"
))
{
return
Config
.
SkyWalking
.
SELF_DEFINE_METHOD_PACKAGE
+
".*"
;
}
return
Config
.
SkyWalking
.
SELF_DEFINE_METHOD_PACKAGE
;
}
}
skywalking-collector/skywalking-sdk-plugin/self-define-interceptor-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
fa2fdb4e
com.ai.cloud.skywalking.self.define.plugin.define.SelfDefineMethodPluginDefine
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录