Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
fa42cd47
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
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,体验更适合开发者的 AI 搜索 >>
提交
fa42cd47
编写于
8月 29, 2017
作者:
A
ascrutae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue that tomcat plugin cannot capture exception
上级
aac05bce
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
92 addition
and
20 deletion
+92
-20
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java
.../skywalking/apm/agent/core/context/util/KeyValuePair.java
+3
-1
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java
...king/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java
+26
-0
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java
...walking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java
+2
-2
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java
...ng/apm/plugin/tomcat78x/define/TomcatInstrumentation.java
+27
-7
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java
...ing/apm/plugin/tomcat78x/TomcatInvokeInterceptorTest.java
+34
-10
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java
浏览文件 @
fa42cd47
...
...
@@ -27,7 +27,9 @@ public class KeyValuePair {
public
KeyWithStringValue
transform
()
{
KeyWithStringValue
.
Builder
keyValueBuilder
=
KeyWithStringValue
.
newBuilder
();
keyValueBuilder
.
setKey
(
key
);
keyValueBuilder
.
setValue
(
value
);
if
(
value
!=
null
)
{
keyValueBuilder
.
setValue
(
value
);
}
return
keyValueBuilder
.
build
();
}
}
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatExceptionInterceptor.java
0 → 100644
浏览文件 @
fa42cd47
package
org.skywalking.apm.plugin.tomcat78x
;
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
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
public
class
TomcatExceptionInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
((
Throwable
)
allArguments
[
2
]);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptor.java
→
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/TomcatIn
vokeIn
terceptor.java
浏览文件 @
fa42cd47
...
...
@@ -16,11 +16,11 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
/**
* {@link TomcatInterceptor} fetch the serialized context data by using {@link HttpServletRequest#getHeader(String)}.
* {@link TomcatIn
vokeIn
terceptor} fetch the serialized context data by using {@link HttpServletRequest#getHeader(String)}.
* The {@link TraceSegment#refs} of current trace segment will reference to the trace
* segment id of the previous level if the serialized context is not null.
*/
public
class
TomcatInterceptor
implements
InstanceMethodsAroundInterceptor
{
public
class
TomcatIn
vokeIn
terceptor
implements
InstanceMethodsAroundInterceptor
{
/**
* * The {@link TraceSegment#refs} of current trace segment will reference to the
...
...
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java
浏览文件 @
fa42cd47
...
...
@@ -8,14 +8,16 @@ import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoin
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
org.skywalking.apm.plugin.tomcat78x.TomcatInterceptor
;
import
org.skywalking.apm.plugin.tomcat78x.TomcatIn
vokeIn
terceptor
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* {@link TomcatInstrumentation} presents that skywalking using class {@link TomcatInterceptor} to
* intercept {@link org.apache.catalina.core.StandardEngineValve#invoke(Request, Response)}.
* {@link TomcatInstrumentation} presents that skywalking using class {@link TomcatInvokeInterceptor} to intercept
* {@link org.apache.catalina.core.StandardWrapperValve#invoke(Request, Response)} and using class {@link
* org.skywalking.apm.plugin.tomcat78x.TomcatExceptionInterceptor} to intercept {@link
* org.apache.catalina.core.StandardWrapperValve#exception(Request, Response, Throwable)}.
*
* @author zhangxin
*/
...
...
@@ -24,12 +26,17 @@ public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefi
/**
* Enhance class.
*/
private
static
final
String
ENHANCE_CLASS
=
"org.apache.catalina.core.Standard
Engine
Valve"
;
private
static
final
String
ENHANCE_CLASS
=
"org.apache.catalina.core.Standard
Wrapper
Valve"
;
/**
*
Intercept class.
*
The intercept class for "invoke" method in the class "org.apache.catalina.core.StandardWrapperValve"
*/
private
static
final
String
INTERCEPT_CLASS
=
"org.skywalking.apm.plugin.tomcat78x.TomcatInterceptor"
;
private
static
final
String
INVOKE_INTERCEPT_CLASS
=
"org.skywalking.apm.plugin.tomcat78x.TomcatInvokeInterceptor"
;
/**
* The intercept class for "exception" method in the class "org.apache.catalina.core.StandardWrapperValve"
*/
private
static
final
String
EXCEPTION_INTERCEPT_CLASS
=
"org.skywalking.apm.plugin.tomcat78x.TomcatExceptionInterceptor"
;
@Override
protected
ClassMatch
enhanceClass
()
{
...
...
@@ -52,13 +59,26 @@ public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefi
@Override
public
String
getMethodsInterceptor
()
{
return
INTERCEPT_CLASS
;
return
IN
VOKE_IN
TERCEPT_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"exception"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
EXCEPTION_INTERCEPT_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
...
...
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatInterceptorTest.java
→
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/org/skywalking/apm/plugin/tomcat78x/TomcatIn
vokeIn
terceptorTest.java
浏览文件 @
fa42cd47
...
...
@@ -37,9 +37,10 @@ import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
TomcatInterceptorTest
{
public
class
TomcatIn
vokeIn
terceptorTest
{
private
TomcatInterceptor
tomcatInterceptor
;
private
TomcatInvokeInterceptor
tomcatInvokeInterceptor
;
private
TomcatExceptionInterceptor
tomcatExceptionInterceptor
;
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
...
...
@@ -59,20 +60,27 @@ public class TomcatInterceptorTest {
private
Object
[]
arguments
;
private
Class
[]
argumentType
;
private
Object
[]
exceptionArguments
;
private
Class
[]
exceptionArgumentType
;
@Before
public
void
setUp
()
throws
Exception
{
tomcatInterceptor
=
new
TomcatInterceptor
();
tomcatInvokeInterceptor
=
new
TomcatInvokeInterceptor
();
tomcatExceptionInterceptor
=
new
TomcatExceptionInterceptor
();
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
[]
{
request
,
response
};
argumentType
=
new
Class
[]
{
request
.
getClass
(),
response
.
getClass
()};
exceptionArguments
=
new
Object
[]
{
request
,
response
,
new
RuntimeException
()};
exceptionArgumentType
=
new
Class
[]
{
request
.
getClass
(),
response
.
getClass
(),
new
RuntimeException
().
getClass
()};
}
@Test
public
void
testWithoutSerializedContextData
()
throws
Throwable
{
tomcatInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
tomcatIn
vokeIn
terceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatIn
vokeIn
terceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -84,8 +92,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
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
tomcatIn
vokeIn
terceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatIn
vokeIn
terceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -97,9 +105,25 @@ public class TomcatInterceptorTest {
@Test
public
void
testWithOccurException
()
throws
Throwable
{
tomcatInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatInterceptor
.
handleMethodException
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
new
RuntimeException
());
tomcatInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
tomcatInvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatInvokeInterceptor
.
handleMethodException
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
new
RuntimeException
());
tomcatInvokeInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertHttpSpan
(
spans
.
get
(
0
));
List
<
LogDataEntity
>
logDataEntities
=
SpanHelper
.
getLogs
(
spans
.
get
(
0
));
assertThat
(
logDataEntities
.
size
(),
is
(
1
));
assertException
(
logDataEntities
.
get
(
0
),
RuntimeException
.
class
);
}
@Test
public
void
testWithTomcatException
()
throws
Throwable
{
tomcatInvokeInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
tomcatExceptionInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
exceptionArguments
,
exceptionArgumentType
,
null
);
tomcatInvokeInterceptor
.
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录