Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
5ab84c2f
S
SkyWalking
项目概览
山不在高_有仙则灵
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
12
Star
0
Fork
2
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
5ab84c2f
编写于
9月 23, 2017
作者:
wu-sheng
提交者:
GitHub
9月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #453 from nutzam/master
add: support nutz mvc and nutz http
上级
d49105f3
13b408e3
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
584 addition
and
2 deletion
+584
-2
apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
...walking/apm/network/trace/component/ComponentsDefine.java
+8
-2
apm-sniffer/apm-agent/pom.xml
apm-sniffer/apm-agent/pom.xml
+10
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/pom.xml
...iffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/pom.xml
+24
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java
...m/plugin/nutz/http/sync/SenderConstructorInterceptor.java
+12
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java
...king/apm/plugin/nutz/http/sync/SenderSendInterceptor.java
+63
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java
...utz/http/sync/define/AbstractNutzHttpInstrumentation.java
+60
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java
...tp/sync/define/NutzHttpFilePostSenderInstrumentation.java
+11
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java
...tz/http/sync/define/NutzHttpGetSenderInstrumentation.java
+12
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java
...z/http/sync/define/NutzHttpPostSenderInstrumentation.java
+13
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/resources/skywalking-plugin.def
.../http-1.x-plugin/src/main/resources/skywalking-plugin.def
+3
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java
...king/apm/plugin/nutz/http/sync/SenderInterceptorTest.java
+114
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/pom.xml
...sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/pom.xml
+30
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java
...ing/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java
+23
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java
...ywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java
+76
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java
.../org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java
+29
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java
...ing/apm/plugin/nutz/mvc/define/ActionInstrumentation.java
+67
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/resources/skywalking-plugin.def
...ation-1.x-plugin/src/main/resources/skywalking-plugin.def
+1
-0
apm-sniffer/apm-sdk-plugin/nutz-plugins/pom.xml
apm-sniffer/apm-sdk-plugin/nutz-plugins/pom.xml
+27
-0
apm-sniffer/apm-sdk-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/pom.xml
+1
-0
未找到文件。
apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
浏览文件 @
5ab84c2f
...
...
@@ -35,7 +35,11 @@ public class ComponentsDefine {
public
static
final
OfficialComponent
SPRING_MVC_ANNOTATION
=
new
OfficialComponent
(
14
,
"SpringMVC"
);
public
static
final
OfficialComponent
STRUTS2
=
new
OfficialComponent
(
14
,
"Struts2"
);
public
static
final
OfficialComponent
STRUTS2
=
new
OfficialComponent
(
15
,
"Struts2"
);
public
static
final
OfficialComponent
NUTZ_MVC_ANNOTATION
=
new
OfficialComponent
(
16
,
"NutzMVC"
);
public
static
final
OfficialComponent
NUTZ_HTTP
=
new
OfficialComponent
(
17
,
"NutzHttp"
);
private
static
ComponentsDefine
instance
=
new
ComponentsDefine
();
...
...
@@ -46,7 +50,7 @@ public class ComponentsDefine {
}
public
ComponentsDefine
()
{
components
=
new
String
[
1
6
];
components
=
new
String
[
1
8
];
addComponent
(
TOMCAT
);
addComponent
(
HTTPCLIENT
);
addComponent
(
DUBBO
);
...
...
@@ -62,6 +66,8 @@ public class ComponentsDefine {
addComponent
(
SPRING_REST_TEMPLATE
);
addComponent
(
SPRING_MVC_ANNOTATION
);
addComponent
(
STRUTS2
);
addComponent
(
NUTZ_MVC_ANNOTATION
);
addComponent
(
NUTZ_HTTP
);
}
private
void
addComponent
(
OfficialComponent
component
)
{
...
...
apm-sniffer/apm-agent/pom.xml
浏览文件 @
5ab84c2f
...
...
@@ -105,6 +105,16 @@
<artifactId>
apm-struts2-2.x-plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-nutz-mvc-annotation-1.x-plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-nutz-http-1.x-plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
<!-- activation -->
<dependency>
...
...
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/pom.xml
0 → 100644
浏览文件 @
5ab84c2f
<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>
nutz-plugins
</artifactId>
<groupId>
org.skywalking
</groupId>
<version>
3.2.1-2017
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apm-nutz-http-1.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
http-1.x-plugin
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
org.nutz
</groupId>
<artifactId>
nutz
</artifactId>
<version>
1.r.62
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderConstructorInterceptor.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
public
class
SenderConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
final
EnhancedInstance
objInst
,
final
Object
[]
allArguments
)
{
objInst
.
setSkyWalkingDynamicField
(
allArguments
[
0
]);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync
;
import
java.lang.reflect.Method
;
import
java.net.URI
;
import
org.nutz.http.Request
;
import
org.nutz.http.Request.METHOD
;
import
org.nutz.http.Response
;
import
org.skywalking.apm.agent.core.context.CarrierItem
;
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
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
public
class
SenderSendInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
final
EnhancedInstance
objInst
,
final
Method
method
,
final
Object
[]
allArguments
,
final
Class
<?>[]
argumentsTypes
,
final
MethodInterceptResult
result
)
throws
Throwable
{
Request
req
=
(
Request
)
objInst
.
getSkyWalkingDynamicField
();
final
URI
requestURL
=
req
.
getUrl
().
toURI
();
final
METHOD
httpMethod
=
req
.
getMethod
();
final
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
String
remotePeer
=
requestURL
.
getHost
()
+
":"
+
requestURL
.
getPort
();
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
requestURL
.
getPath
(),
contextCarrier
,
remotePeer
);
span
.
setComponent
(
ComponentsDefine
.
NUTZ_HTTP
);
Tags
.
URL
.
set
(
span
,
requestURL
.
getScheme
()
+
"://"
+
requestURL
.
getHost
()
+
":"
+
requestURL
.
getPort
()
+
requestURL
.
getPath
());
Tags
.
HTTP
.
METHOD
.
set
(
span
,
httpMethod
.
toString
());
SpanLayer
.
asHttp
(
span
);
CarrierItem
next
=
contextCarrier
.
items
();
while
(
next
.
hasNext
())
{
next
=
next
.
next
();
req
.
getHeader
().
set
(
next
.
getHeadKey
(),
next
.
getHeadValue
());
}
}
@Override
public
Object
afterMethod
(
final
EnhancedInstance
objInst
,
final
Method
method
,
final
Object
[]
allArguments
,
final
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Response
response
=
(
Response
)
ret
;
int
statusCode
=
response
.
getStatus
();
AbstractSpan
span
=
ContextManager
.
activeSpan
();
if
(
statusCode
>=
400
)
{
span
.
errorOccurred
();
Tags
.
STATUS_CODE
.
set
(
span
,
Integer
.
toString
(
statusCode
));
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
final
EnhancedInstance
objInst
,
final
Method
method
,
final
Object
[]
allArguments
,
final
Class
<?>[]
argumentsTypes
,
final
Throwable
t
)
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
(
t
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/AbstractNutzHttpInstrumentation.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync.define
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
net.bytebuddy.matcher.ElementMatchers
;
public
abstract
class
AbstractNutzHttpInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
DO_SEND_METHOD_NAME
=
"send"
;
private
static
final
String
DO_SEND_INTERCEPTOR
=
"org.skywalking.apm.plugin.nutz.http.sync.SenderSendInterceptor"
;
private
static
final
String
DO_CONSTRUCTOR_INTERCEPTOR
=
"org.skywalking.apm.plugin.nutz.http.sync.SenderConstructorInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
ElementMatchers
.
takesArguments
(
1
);
}
@Override
public
String
getConstructorInterceptor
()
{
return
DO_CONSTRUCTOR_INTERCEPTOR
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
DO_SEND_METHOD_NAME
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
DO_SEND_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
protected
abstract
ClassMatch
enhanceClass
();
}
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpFilePostSenderInstrumentation.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync.define
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
org.skywalking.apm.agent.core.plugin.match.NameMatch
;
public
class
NutzHttpFilePostSenderInstrumentation
extends
AbstractNutzHttpInstrumentation
{
protected
ClassMatch
enhanceClass
()
{
return
NameMatch
.
byName
(
"org.nutz.http.sender.FilePostSender"
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpGetSenderInstrumentation.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync.define
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
org.skywalking.apm.agent.core.plugin.match.NameMatch
;
public
class
NutzHttpGetSenderInstrumentation
extends
AbstractNutzHttpInstrumentation
{
@Override
protected
ClassMatch
enhanceClass
()
{
return
NameMatch
.
byName
(
"org.nutz.http.sender.GetSender"
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/http/sync/define/NutzHttpPostSenderInstrumentation.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync.define
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
org.skywalking.apm.agent.core.plugin.match.NameMatch
;
public
class
NutzHttpPostSenderInstrumentation
extends
AbstractNutzHttpInstrumentation
{
@Override
protected
ClassMatch
enhanceClass
()
{
return
NameMatch
.
byName
(
"org.nutz.http.sender.PostSender"
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
5ab84c2f
nutz-http-1.x=org.skywalking.apm.plugin.nutz.http.sync.define.NutzHttpGetSenderInstrumentation
nutz-http-1.x=org.skywalking.apm.plugin.nutz.http.sync.define.NutzHttpPostSenderInstrumentation
nutz-http-1.x=org.skywalking.apm.plugin.nutz.http.sync.define.NutzHttpFilePostSenderInstrumentation
apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/test/java/org/skywalking/apm/plugin/nutz/http/sync/SenderInterceptorTest.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.http.sync
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.nutz.http.Request
;
import
org.nutz.http.Request.METHOD
;
import
org.nutz.http.Response
;
import
org.nutz.http.Sender
;
import
org.nutz.http.sender.FilePostSender
;
import
org.nutz.http.sender.GetSender
;
import
org.nutz.http.sender.PostSender
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.test.helper.SegmentHelper
;
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
;
@RunWith
(
org
.
powermock
.
modules
.
junit4
.
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
SenderInterceptorTest
{
@SegmentStoragePoint
public
SegmentStorage
segmentStorage
;
@Rule
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
@Mock
private
EnhancedInstance
enhancedInstance
;
@Mock
Response
resp
;
SenderConstructorInterceptor
constructorInterceptPoint
;
SenderSendInterceptor
senderSendInterceptor
;
Method
sendMethod
;
Object
[]
allArguments
;
Class
<?>[]
argumentsTypes
;
@Before
public
void
setUp
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
constructorInterceptPoint
=
new
SenderConstructorInterceptor
();
senderSendInterceptor
=
new
SenderSendInterceptor
();
}
public
void
setupSender
(
Class
<?
extends
Sender
>
klass
)
throws
NoSuchMethodException
,
SecurityException
{
sendMethod
=
klass
.
getMethod
(
"send"
);
allArguments
=
new
Object
[
0
];
argumentsTypes
=
new
Class
<?>[
0
];
}
@Test
public
void
test_constructor
()
{
Request
request
=
Request
.
create
(
"https://nutz.cn/yvr/list"
,
METHOD
.
GET
);
constructorInterceptPoint
.
onConstruct
(
enhancedInstance
,
new
Object
[]{
request
});
verify
(
enhancedInstance
,
times
(
1
)).
setSkyWalkingDynamicField
(
request
);
}
@Test
public
void
test_getsender_send
()
throws
NoSuchMethodException
,
SecurityException
,
Throwable
{
setupSender
(
GetSender
.
class
);
_sender_sender_test
();
}
@Test
public
void
test_postsender_send
()
throws
NoSuchMethodException
,
SecurityException
,
Throwable
{
setupSender
(
PostSender
.
class
);
_sender_sender_test
();
}
@Test
public
void
test_filepostsender_send
()
throws
NoSuchMethodException
,
SecurityException
,
Throwable
{
setupSender
(
FilePostSender
.
class
);
_sender_sender_test
();
}
protected
void
_sender_sender_test
()
throws
Throwable
{
Request
request
=
Request
.
create
(
"https://nutz.cn/yvr/list"
,
METHOD
.
GET
);
constructorInterceptPoint
.
onConstruct
(
enhancedInstance
,
new
Object
[]{
request
});
verify
(
enhancedInstance
,
times
(
1
)).
setSkyWalkingDynamicField
(
request
);
when
(
enhancedInstance
.
getSkyWalkingDynamicField
()).
thenReturn
(
request
);
when
(
resp
.
getStatus
()).
thenReturn
(
200
);
senderSendInterceptor
.
beforeMethod
(
enhancedInstance
,
sendMethod
,
allArguments
,
argumentsTypes
,
null
);
senderSendInterceptor
.
afterMethod
(
enhancedInstance
,
sendMethod
,
allArguments
,
argumentsTypes
,
resp
);
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertThat
(
spans
.
get
(
0
).
getOperationName
(),
is
(
"/yvr/list"
));
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/pom.xml
0 → 100644
浏览文件 @
5ab84c2f
<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>
nutz-plugins
</artifactId>
<groupId>
org.skywalking
</groupId>
<version>
3.2.1-2017
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apm-nutz-mvc-annotation-1.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
mvc-annotation-1.x-plugin
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
org.nutz
</groupId>
<artifactId>
nutz
</artifactId>
<version>
1.r.62
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
3.1.0
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionConstructorInterceptor.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.mvc
;
import
org.nutz.mvc.annotation.At
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
/**
*
* @author wendal
*/
public
class
ActionConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
String
basePath
=
""
;
At
basePathRequestMapping
=
objInst
.
getClass
().
getAnnotation
(
At
.
class
);
if
(
basePathRequestMapping
!=
null
)
{
basePath
=
basePathRequestMapping
.
value
()[
0
];
}
PathMappingCache
pathMappingCache
=
new
PathMappingCache
(
basePath
);
objInst
.
setSkyWalkingDynamicField
(
pathMappingCache
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/ActionMethodInterceptor.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.mvc
;
import
java.lang.reflect.Method
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.nutz.mvc.Mvcs
;
import
org.nutz.mvc.annotation.At
;
import
org.skywalking.apm.agent.core.context.CarrierItem
;
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
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
/**
* The <code>ActionMethodInterceptor</code> only use the first mapping value.
*
* @See {@link ActionConstructorInterceptor} to explain why we are doing this.
* @author wendal
*/
public
class
ActionMethodInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
PathMappingCache
pathMappingCache
=
(
PathMappingCache
)
objInst
.
getSkyWalkingDynamicField
();
String
requestURL
=
pathMappingCache
.
findPathMapping
(
method
);
if
(
requestURL
==
null
)
{
At
methodRequestMapping
=
method
.
getAnnotation
(
At
.
class
);
if
(
methodRequestMapping
.
value
().
length
>
0
)
{
requestURL
=
methodRequestMapping
.
value
()[
0
];
}
else
{
requestURL
=
""
;
}
pathMappingCache
.
addPathMapping
(
method
,
requestURL
);
requestURL
=
pathMappingCache
.
findPathMapping
(
method
);
}
HttpServletRequest
request
=
Mvcs
.
getReq
();
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
CarrierItem
next
=
contextCarrier
.
items
();
while
(
next
.
hasNext
())
{
next
=
next
.
next
();
next
.
setHeadValue
(
request
.
getHeader
(
next
.
getHeadKey
()));
}
AbstractSpan
span
=
ContextManager
.
createEntrySpan
(
requestURL
,
contextCarrier
);
Tags
.
URL
.
set
(
span
,
request
.
getRequestURL
().
toString
());
Tags
.
HTTP
.
METHOD
.
set
(
span
,
request
.
getMethod
());
span
.
setComponent
(
ComponentsDefine
.
NUTZ_MVC_ANNOTATION
);
SpanLayer
.
asHttp
(
span
);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
HttpServletResponse
response
=
Mvcs
.
getResp
();
AbstractSpan
span
=
ContextManager
.
activeSpan
();
if
(
response
.
getStatus
()
>=
400
)
{
span
.
errorOccurred
();
Tags
.
STATUS_CODE
.
set
(
span
,
Integer
.
toString
(
response
.
getStatus
()));
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
(
t
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/PathMappingCache.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.mvc
;
import
java.lang.reflect.Method
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* The <code>PathMappingCache</code> represents a mapping cache.
* key: {@link Method}
* value: the url pattern
*
* @author wendal
*/
public
class
PathMappingCache
{
private
String
classPath
=
""
;
private
ConcurrentHashMap
<
Method
,
String
>
methodPathMapping
=
new
ConcurrentHashMap
<
Method
,
String
>();
public
PathMappingCache
(
String
classPath
)
{
this
.
classPath
=
classPath
;
}
public
String
findPathMapping
(
Method
method
)
{
return
methodPathMapping
.
get
(
method
);
}
public
void
addPathMapping
(
Method
method
,
String
methodPath
)
{
methodPathMapping
.
put
(
method
,
classPath
+
methodPath
);
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/java/org/skywalking/apm/plugin/nutz/mvc/define/ActionInstrumentation.java
0 → 100644
浏览文件 @
5ab84c2f
package
org.skywalking.apm.plugin.nutz.mvc.define
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
isAnnotatedWith
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
ClassAnnotationMatch
.
byClassAnnotationMatch
;
import
org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
public
class
ActionInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
static
final
String
ENHANCE_ANNOTATION
=
"org.nutz.mvc.annotation.At"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
"org.skywalking.apm.plugin.nutz.mvc.ActionConstructorInterceptor"
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
isAnnotatedWith
(
named
(
"org.nutz.mvc.annotation.At"
));
}
@Override
public
String
getMethodsInterceptor
()
{
return
"org.skywalking.apm.plugin.nutz.mvc.ActionMethodInterceptor"
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byClassAnnotationMatch
(
getEnhanceAnnotations
());
}
protected
String
[]
getEnhanceAnnotations
()
{
return
new
String
[]
{
ENHANCE_ANNOTATION
};
}
}
apm-sniffer/apm-sdk-plugin/nutz-plugins/mvc-annotation-1.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
5ab84c2f
nutz-mvc-annotation-1.x=org.skywalking.apm.plugin.nutz.mvc.define.ActionInstrumentation
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/nutz-plugins/pom.xml
0 → 100644
浏览文件 @
5ab84c2f
<?xml version="1.0" encoding="UTF-8"?>
<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"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-sdk-plugin
</artifactId>
<version>
3.2.1-2017
</version>
</parent>
<artifactId>
nutz-plugins
</artifactId>
<modules>
<!-- <module>dao-1.x-plugin</module> -->
<module>
http-1.x-plugin
</module>
<module>
mvc-annotation-1.x-plugin
</module>
</modules>
<packaging>
pom
</packaging>
<name>
apm-sdk-plugin
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
</project>
apm-sniffer/apm-sdk-plugin/pom.xml
浏览文件 @
5ab84c2f
...
...
@@ -24,6 +24,7 @@
<module>
resin-4.x-plugin
</module>
<module>
spring-plugins
</module>
<module>
struts2-2.x-plugin
</module>
<module>
nutz-plugins
</module>
</modules>
<packaging>
pom
</packaging>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录