Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
0f0b56db
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
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,发现更多精彩内容 >>
提交
0f0b56db
编写于
6月 10, 2018
作者:
X
Xin,Zhang
提交者:
wu-sheng
6月 10, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #1280: Modify tomcat interceptor (#1325)
上级
5f81c006
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
351 addition
and
39 deletion
+351
-39
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/ForwardInterceptor.java
...alking/apm/plugin/jetty/v9/server/ForwardInterceptor.java
+61
-0
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java
...walking/apm/plugin/jetty/v9/server/HandleInterceptor.java
+2
-2
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/DispatcherInstrumentation.java
...gin/jetty/v9/server/define/DispatcherInstrumentation.java
+73
-0
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java
...m/plugin/jetty/v9/server/define/JettyInstrumentation.java
+4
-6
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
-0
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java
...ing/apm/plugin/jetty/v9/server/HandleInterceptorTest.java
+47
-29
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java
...e/skywalking/apm/plugin/spring/mvc/commons/Constants.java
+2
-0
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java
...ng/mvc/commons/interceptor/AbstractMethodInterceptor.java
+20
-0
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/ForwardInterceptor.java
...e/skywalking/apm/plugin/tomcat78x/ForwardInterceptor.java
+64
-0
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/ApplicationDispatcherInstrumentation.java
...omcat78x/define/ApplicationDispatcherInstrumentation.java
+74
-0
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java
...ng/apm/plugin/tomcat78x/define/TomcatInstrumentation.java
+2
-2
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def
...t-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def
+1
-0
未找到文件。
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/ForwardInterceptor.java
0 → 100644
浏览文件 @
0f0b56db
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package
org.apache.skywalking.apm.plugin.jetty.v9.server
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
public
class
ForwardInterceptor
implements
InstanceMethodsAroundInterceptor
,
InstanceConstructorInterceptor
{
private
static
final
String
FORWARD_REQUEST_FLAG
=
"SW_FORWARD_REQUEST_FLAG"
;
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
if
(
ContextManager
.
isActive
())
{
AbstractSpan
abstractTracingSpan
=
ContextManager
.
activeSpan
();
Map
<
String
,
String
>
eventMap
=
new
HashMap
<
String
,
String
>();
eventMap
.
put
(
"forward-url"
,
(
String
)
objInst
.
getSkyWalkingDynamicField
());
abstractTracingSpan
.
log
(
System
.
currentTimeMillis
(),
eventMap
);
ContextManager
.
getRuntimeContext
().
put
(
FORWARD_REQUEST_FLAG
,
true
);
}
}
@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
)
{
}
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
objInst
.
setSkyWalkingDynamicField
(
allArguments
[
2
]);
}
}
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptor.java
浏览文件 @
0f0b56db
...
...
@@ -38,7 +38,7 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
HttpChannel
httpChannel
=
(
HttpChannel
)
allArguments
[
0
]
;
HttpChannel
httpChannel
=
(
HttpChannel
)
objInst
;
HttpServletRequest
servletRequest
=
httpChannel
.
getRequest
();
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
...
...
@@ -59,7 +59,7 @@ public class HandleInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
HttpChannel
httpChannel
=
(
HttpChannel
)
allArguments
[
0
]
;
HttpChannel
httpChannel
=
(
HttpChannel
)
objInst
;
HttpServletResponse
servletResponse
=
httpChannel
.
getResponse
();
AbstractSpan
span
=
ContextManager
.
activeSpan
();
if
(
servletResponse
.
getStatus
()
>=
400
)
{
...
...
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/DispatcherInstrumentation.java
0 → 100644
浏览文件 @
0f0b56db
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package
org.apache.skywalking.apm.plugin.jetty.v9.server.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
bytebuddy
.
ArgumentTypeNameMatch
.
takesArgumentWithType
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
public
class
DispatcherInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.eclipse.jetty.server.Dispatcher"
;
public
static
final
String
INTERCEPT_CLASS
=
"org.apache.skywalking.apm.plugin.jetty.v9.server.ForwardInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
takesArgumentWithType
(
2
,
"java.lang.String"
);
}
@Override
public
String
getConstructorInterceptor
()
{
return
INTERCEPT_CLASS
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"forward"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
INTERCEPT_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
ENHANCE_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/server/define/JettyInstrumentation.java
浏览文件 @
0f0b56db
...
...
@@ -16,19 +16,17 @@
*
*/
package
org.apache.skywalking.apm.plugin.jetty.v9.server.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
bytebuddy
.
ArgumentTypeNameMatch
.
takesArgumentWithType
;
/**
* {@link JettyInstrumentation} enhance the <code>handle</code> method in <code>org.eclipse.jetty.server.handler.HandlerList</code>
...
...
@@ -38,7 +36,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentType
*/
public
class
JettyInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.eclipse.jetty.server.
Server
"
;
private
static
final
String
ENHANCE_CLASS
=
"org.eclipse.jetty.server.
HttpChannel
"
;
private
static
final
String
ENHANCE_METHOD
=
"handle"
;
private
static
final
String
INTERCEPTOR_CLASS
=
"org.apache.skywalking.apm.plugin.jetty.v9.server.HandleInterceptor"
;
...
...
@@ -50,7 +48,7 @@ public class JettyInstrumentation extends ClassInstanceMethodsEnhancePluginDefin
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
ENHANCE_METHOD
)
.
and
(
takesArgumentWithType
(
0
,
"org.eclipse.jetty.server.HttpChannel"
))
;
return
named
(
ENHANCE_METHOD
);
}
@Override
public
String
getMethodsInterceptor
()
{
...
...
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
0f0b56db
...
...
@@ -15,3 +15,4 @@
# limitations under the License.
jetty-server-9.x=org.apache.skywalking.apm.plugin.jetty.v9.server.define.JettyInstrumentation
jetty-server-9.x=org.apache.skywalking.apm.plugin.jetty.v9.server.define.DispatcherInstrumentation
apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-server-9.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jetty/v9/server/HandleInterceptorTest.java
浏览文件 @
0f0b56db
...
...
@@ -16,22 +16,9 @@
*
*/
package
org.apache.skywalking.apm.plugin.jetty.v9.server
;
import
java.util.List
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStorage
;
import
org.apache.skywalking.apm.agent.test.tools.SpanAssert
;
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
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
org.apache.skywalking.apm.agent.core.context.SW3CarrierItem
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity
;
...
...
@@ -44,14 +31,31 @@ import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
import
org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper
;
import
org.apache.skywalking.apm.agent.test.helper.SpanHelper
;
import
org.apache.skywalking.apm.agent.test.tools.AgentServiceRule
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStorage
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint
;
import
org.apache.skywalking.apm.agent.test.tools.SpanAssert
;
import
org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner
;
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.eclipse.jetty.io.EndPoint
;
import
org.eclipse.jetty.server.Connector
;
import
org.eclipse.jetty.server.HttpChannel
;
import
org.eclipse.jetty.server.HttpConfiguration
;
import
org.eclipse.jetty.server.HttpInput
;
import
org.eclipse.jetty.server.HttpTransport
;
import
org.eclipse.jetty.server.Request
;
import
org.eclipse.jetty.server.Response
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertComponent
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertComponent
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
...
...
@@ -73,10 +77,7 @@ public class HandleInterceptorTest {
private
MethodInterceptResult
methodInterceptResult
;
@Mock
private
EnhancedInstance
enhancedInstance
;
@Mock
private
HttpChannel
httpChannel
;
private
MockService
service
;
private
Object
[]
arguments
;
private
Class
[]
argumentType
;
...
...
@@ -87,17 +88,17 @@ public class HandleInterceptorTest {
when
(
request
.
getRequestURI
()).
thenReturn
(
"/test/testRequestURL"
);
when
(
request
.
getRequestURL
()).
thenReturn
(
new
StringBuffer
(
"http://localhost:8080/test/testRequestURL"
));
when
(
response
.
getStatus
()).
thenReturn
(
200
);
when
(
httpChannel
.
getResponse
()).
thenReturn
(
response
);
when
(
httpChannel
.
getRequest
()).
thenReturn
(
request
);
arguments
=
new
Object
[]
{
httpChannel
};
argumentType
=
new
Class
[]
{
httpChannel
.
getClass
()};
when
(
service
.
getResponse
()).
thenReturn
(
response
);
when
(
service
.
getRequest
()).
thenReturn
(
request
);
arguments
=
new
Object
[]
{
service
};
argumentType
=
new
Class
[]
{
service
.
getClass
()};
}
@Test
public
void
testWithoutSerializedContextData
()
throws
Throwable
{
jettyInvokeInterceptor
.
beforeMethod
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jettyInvokeInterceptor
.
afterMethod
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
null
);
jettyInvokeInterceptor
.
beforeMethod
(
servi
ce
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jettyInvokeInterceptor
.
afterMethod
(
servi
ce
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -109,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*"
);
jettyInvokeInterceptor
.
beforeMethod
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jettyInvokeInterceptor
.
afterMethod
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
null
);
jettyInvokeInterceptor
.
beforeMethod
(
servi
ce
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jettyInvokeInterceptor
.
afterMethod
(
servi
ce
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -122,9 +123,9 @@ public class HandleInterceptorTest {
@Test
public
void
testWithOccurException
()
throws
Throwable
{
jettyInvokeInterceptor
.
beforeMethod
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jettyInvokeInterceptor
.
handleMethodException
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
new
RuntimeException
());
jettyInvokeInterceptor
.
afterMethod
(
enhancedInstan
ce
,
null
,
arguments
,
argumentType
,
null
);
jettyInvokeInterceptor
.
beforeMethod
(
servi
ce
,
null
,
arguments
,
argumentType
,
methodInterceptResult
);
jettyInvokeInterceptor
.
handleMethodException
(
servi
ce
,
null
,
arguments
,
argumentType
,
new
RuntimeException
());
jettyInvokeInterceptor
.
afterMethod
(
servi
ce
,
null
,
arguments
,
argumentType
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
...
...
@@ -149,4 +150,21 @@ public class HandleInterceptorTest {
assertThat
(
span
.
isEntry
(),
is
(
true
));
SpanAssert
.
assertLayer
(
span
,
SpanLayer
.
HTTP
);
}
public
static
class
MockService
extends
HttpChannel
implements
EnhancedInstance
{
public
MockService
(
Connector
connector
,
HttpConfiguration
configuration
,
EndPoint
endPoint
,
HttpTransport
transport
,
HttpInput
input
)
{
super
(
connector
,
configuration
,
endPoint
,
transport
,
input
);
}
@Override
public
Object
getSkyWalkingDynamicField
()
{
return
null
;
}
@Override
public
void
setSkyWalkingDynamicField
(
Object
value
)
{
}
}
}
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/Constants.java
浏览文件 @
0f0b56db
...
...
@@ -39,4 +39,6 @@ public class Constants {
public
static
final
String
RESPONSE_KEY_IN_RUNTIME_CONTEXT
=
"SW_RESPONSE"
;
public
static
final
String
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
=
"ISOLATE_STRATEGY"
;
public
static
final
String
FORWARD_REQUEST_FLAG
=
"SW_FORWARD_REQUEST_FLAG"
;
}
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java
浏览文件 @
0f0b56db
...
...
@@ -33,6 +33,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
FORWARD_REQUEST_FLAG
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
REQUEST_KEY_IN_RUNTIME_CONTEXT
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
spring
.
mvc
.
commons
.
Constants
.
RESPONSE_KEY_IN_RUNTIME_CONTEXT
;
...
...
@@ -46,6 +47,16 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
Boolean
forwardRequestFlag
=
(
Boolean
)
ContextManager
.
getRuntimeContext
().
get
(
FORWARD_REQUEST_FLAG
);
/**
* Spring MVC plugin do nothing if current request is forward request.
* Ref: https://github.com/apache/incubator-skywalking/pull/1325
*/
if
(
forwardRequestFlag
!=
null
&&
forwardRequestFlag
)
{
return
;
}
EnhanceRequireObjectCache
pathMappingCache
=
(
EnhanceRequireObjectCache
)
objInst
.
getSkyWalkingDynamicField
();
String
requestURL
=
pathMappingCache
.
findPathMapping
(
method
);
if
(
requestURL
==
null
)
{
...
...
@@ -78,6 +89,15 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Boolean
forwardRequestFlag
=
(
Boolean
)
ContextManager
.
getRuntimeContext
().
get
(
FORWARD_REQUEST_FLAG
);
/**
* Spring MVC plugin do nothing if current request is forward request.
* Ref: https://github.com/apache/incubator-skywalking/pull/1325
*/
if
(
forwardRequestFlag
!=
null
&&
forwardRequestFlag
)
{
return
ret
;
}
String
hystrixIsolateStrategy
=
(
String
)
ContextManager
.
getRuntimeContext
().
get
(
ISOLATE_STRATEGY_KEY_IN_RUNNING_CONTEXT
);
HttpServletResponse
response
=
(
HttpServletResponse
)
ContextManager
.
getRuntimeContext
().
get
(
RESPONSE_KEY_IN_RUNTIME_CONTEXT
);
...
...
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/ForwardInterceptor.java
0 → 100644
浏览文件 @
0f0b56db
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package
org.apache.skywalking.apm.plugin.tomcat78x
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
public
class
ForwardInterceptor
implements
InstanceMethodsAroundInterceptor
,
InstanceConstructorInterceptor
{
private
static
final
String
FORWARD_REQUEST_FLAG
=
"SW_FORWARD_REQUEST_FLAG"
;
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
if
(
ContextManager
.
isActive
())
{
AbstractSpan
abstractTracingSpan
=
ContextManager
.
activeSpan
();
Map
<
String
,
String
>
eventMap
=
new
HashMap
<
String
,
String
>();
eventMap
.
put
(
"forward-url"
,
(
String
)
objInst
.
getSkyWalkingDynamicField
());
abstractTracingSpan
.
log
(
System
.
currentTimeMillis
(),
eventMap
);
ContextManager
.
getRuntimeContext
().
put
(
FORWARD_REQUEST_FLAG
,
true
);
}
}
@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
)
{
}
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
objInst
.
setSkyWalkingDynamicField
(
allArguments
[
1
]);
}
}
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/ApplicationDispatcherInstrumentation.java
0 → 100644
浏览文件 @
0f0b56db
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.tomcat78x.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
public
class
ApplicationDispatcherInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.apache.catalina.core.ApplicationDispatcher"
;
private
static
final
String
ENHANCE_METHOD
=
"forward"
;
public
static
final
String
INTERCEPTOR_CLASS
=
"org.apache.skywalking.apm.plugin.tomcat78x.ForwardInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
INTERCEPTOR_CLASS
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
ENHANCE_METHOD
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
INTERCEPTOR_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
ENHANCE_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/define/TomcatInstrumentation.java
浏览文件 @
0f0b56db
...
...
@@ -37,7 +37,7 @@ public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefi
/**
* Enhance class.
*/
private
static
final
String
ENHANCE_CLASS
=
"org.apache.catalina.core.Standard
Wrapper
Valve"
;
private
static
final
String
ENHANCE_CLASS
=
"org.apache.catalina.core.Standard
Host
Valve"
;
/**
* The intercept class for "invoke" method in the class "org.apache.catalina.core.StandardWrapperValve"
...
...
@@ -80,7 +80,7 @@ public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefi
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"
exception
"
);
return
named
(
"
throwable
"
);
}
@Override
public
String
getMethodsInterceptor
()
{
...
...
apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
0f0b56db
...
...
@@ -15,3 +15,4 @@
# limitations under the License.
tomcat-7.x/8.x=org.apache.skywalking.apm.plugin.tomcat78x.define.TomcatInstrumentation
tomcat-7.x/8.x=org.apache.skywalking.apm.plugin.tomcat78x.define.ApplicationDispatcherInstrumentation
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录