Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
cc2007ee
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,发现更多精彩内容 >>
提交
cc2007ee
编写于
10月 11, 2017
作者:
A
ascrutae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix jetty plugin works incorrect
上级
cf743129
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
26 deletion
+32
-26
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java
...walking/apm/plugin/jetty/v9/server/HandleInterceptor.java
+6
-4
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java
...m/plugin/jetty/v9/server/define/JettyInstrumentation.java
+5
-4
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def
...erver-9.x-plugin/src/main/resources/skywalking-plugin.def
+1
-1
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java
...ing/apm/plugin/jetty/v9/server/HandleInterceptorTest.java
+20
-17
未找到文件。
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java
浏览文件 @
cc2007ee
...
...
@@ -21,6 +21,7 @@ package org.skywalking.apm.plugin.jetty.v9.server;
import
java.lang.reflect.Method
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.eclipse.jetty.server.HttpChannel
;
import
org.skywalking.apm.agent.core.context.CarrierItem
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
...
...
@@ -36,8 +37,8 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
String
requestURI
=
(
String
)
allArguments
[
0
];
HttpServletRequest
servletRequest
=
(
HttpServletRequest
)
allArguments
[
2
]
;
HttpChannel
httpChannel
=
(
HttpChannel
)
allArguments
[
0
];
HttpServletRequest
servletRequest
=
httpChannel
.
getRequest
()
;
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
...
...
@@ -47,7 +48,7 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
next
.
setHeadValue
(
servletRequest
.
getHeader
(
next
.
getHeadKey
()));
}
AbstractSpan
span
=
ContextManager
.
createEntrySpan
(
requestURI
,
contextCarrier
);
AbstractSpan
span
=
ContextManager
.
createEntrySpan
(
servletRequest
.
getRequestURI
()
,
contextCarrier
);
Tags
.
URL
.
set
(
span
,
servletRequest
.
getRequestURL
().
toString
());
Tags
.
HTTP
.
METHOD
.
set
(
span
,
servletRequest
.
getMethod
());
span
.
setComponent
(
ComponentsDefine
.
JETTY_SERVER
);
...
...
@@ -57,7 +58,8 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
HttpServletResponse
servletResponse
=
(
HttpServletResponse
)
allArguments
[
3
];
HttpChannel
httpChannel
=
(
HttpChannel
)
allArguments
[
0
];
HttpServletResponse
servletResponse
=
httpChannel
.
getResponse
();
AbstractSpan
span
=
ContextManager
.
activeSpan
();
if
(
servletResponse
.
getStatus
()
>=
400
)
{
span
.
errorOccurred
();
...
...
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/
HandlerList
Instrumentation.java
→
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/skywalking/apm/plugin/jetty/v9/server/define/
Jetty
Instrumentation.java
浏览文件 @
cc2007ee
...
...
@@ -26,17 +26,18 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMet
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
bytebuddy
.
ArgumentTypeNameMatch
.
takesArgumentWithType
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* {@link
HandlerList
Instrumentation} enhance the <code>handle</code> method in <code>org.eclipse.jetty.server.handler.HandlerList</code>
* {@link
Jetty
Instrumentation} enhance the <code>handle</code> method in <code>org.eclipse.jetty.server.handler.HandlerList</code>
* by <code>org.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor</code>
*
* @author zhangxin
*/
public
class
HandlerList
Instrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
class
Jetty
Instrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.eclipse.jetty.server.
handler.HandlerList
"
;
private
static
final
String
ENHANCE_CLASS
=
"org.eclipse.jetty.server.
Server
"
;
private
static
final
String
ENHANCE_METHOD
=
"handle"
;
private
static
final
String
INTERCEPTOR_CLASS
=
"org.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor"
;
...
...
@@ -48,7 +49,7 @@ public class HandlerListInstrumentation extends ClassInstanceMethodsEnhancePlugi
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
ENHANCE_METHOD
);
return
named
(
ENHANCE_METHOD
)
.
and
(
takesArgumentWithType
(
0
,
"org.eclipse.jetty.server.HttpChannel"
))
;
}
@Override
public
String
getMethodsInterceptor
()
{
...
...
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
cc2007ee
jetty-server-9.x=org.skywalking.apm.plugin.jetty.v9.server.define.
HandlerList
Instrumentation
jetty-server-9.x=org.skywalking.apm.plugin.jetty.v9.server.define.
Jetty
Instrumentation
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java
浏览文件 @
cc2007ee
...
...
@@ -19,9 +19,9 @@
package
org.skywalking.apm.plugin.jetty.v9.server
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.eclipse.jetty.server.HttpChannel
;
import
org.eclipse.jetty.server.Request
;
import
org.eclipse.jetty.server.Response
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -58,7 +58,7 @@ import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag;
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
HandleInterceptorTest
{
private
HandleInterceptor
tomcat
InvokeInterceptor
;
private
HandleInterceptor
jetty
InvokeInterceptor
;
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
...
...
@@ -66,36 +66,39 @@ public class HandleInterceptorTest {
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
@Mock
private
HttpServlet
Request
request
;
private
Request
request
;
@Mock
private
Request
baseRequest
;
@Mock
private
HttpServletResponse
response
;
private
Response
response
;
@Mock
private
MethodInterceptResult
methodInterceptResult
;
@Mock
private
EnhancedInstance
enhancedInstance
;
@Mock
private
HttpChannel
httpChannel
;
private
Object
[]
arguments
;
private
Class
[]
argumentType
;
@Before
public
void
setUp
()
throws
Exception
{
tomcat
InvokeInterceptor
=
new
HandleInterceptor
();
jetty
InvokeInterceptor
=
new
HandleInterceptor
();
when
(
request
.
getRequestURI
()).
thenReturn
(
"/test/testRequestURL"
);
when
(
request
.
getRequestURL
()).
thenReturn
(
new
StringBuffer
(
"http://localhost:8080/test/testRequestURL"
));
when
(
response
.
getStatus
()).
thenReturn
(
200
);
arguments
=
new
Object
[]
{
"/test/testRequestURL"
,
baseRequest
,
request
,
response
};
argumentType
=
new
Class
[]
{
String
.
class
,
baseRequest
.
getClass
(),
request
.
getClass
(),
response
.
getClass
()};
when
(
httpChannel
.
getResponse
()).
thenReturn
(
response
);
when
(
httpChannel
.
getRequest
()).
thenReturn
(
request
);
arguments
=
new
Object
[]
{
httpChannel
};
argumentType
=
new
Class
[]
{
httpChannel
.
getClass
()};
}
@Test
public
void
testWithoutSerializedContextData
()
throws
Throwable
{
tomcat
InvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcat
InvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
jetty
InvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jetty
InvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -107,8 +110,8 @@ public class HandleInterceptorTest {
public
void
testWithSerializedContextData
()
throws
Throwable
{
when
(
request
.
getHeader
(
SW3CarrierItem
.
HEADER_NAME
)).
thenReturn
(
"1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"
);
tomcat
InvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcat
InvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
jetty
InvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jetty
InvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -120,9 +123,9 @@ public class HandleInterceptorTest {
@Test
public
void
testWithOccurException
()
throws
Throwable
{
tomcat
InvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcat
InvokeInterceptor
.
handleMethodException
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
new
RuntimeException
());
tomcat
InvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
jetty
InvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jetty
InvokeInterceptor
.
handleMethodException
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
new
RuntimeException
());
jetty
InvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录