Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
润土的好友猹
SkyWalking
提交
1c4905ef
S
SkyWalking
项目概览
润土的好友猹
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
9
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,发现更多精彩内容 >>
提交
1c4905ef
编写于
5月 10, 2017
作者:
柏
柏杨 Bai Yang
提交者:
wu-sheng
5月 10, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add resin plugin (#187)
* add plugins for resin-3.x and resin-4.x
上级
4a560433
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
671 addition
and
0 deletion
+671
-0
.travis.yml
.travis.yml
+1
-0
apm-sniffer/apm-agent/pom.xml
apm-sniffer/apm-agent/pom.xml
+10
-0
apm-sniffer/apm-sdk-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/pom.xml
+2
-0
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/pom.xml
+56
-0
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java
...rg/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java
+72
-0
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java
...ng/apm/plugin/resin/v3/define/ResinV3Instrumentation.java
+55
-0
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/resources/skywalking-plugin.def
...resin-3.x-plugin/src/main/resources/skywalking-plugin.def
+1
-0
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java
...kywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java
+147
-0
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/pom.xml
+57
-0
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java
...rg/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java
+70
-0
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java
...ng/apm/plugin/resin/v4/define/ResinV4Instrumentation.java
+54
-0
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/resources/skywalking-plugin.def
...resin-4.x-plugin/src/main/resources/skywalking-plugin.def
+1
-0
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java
...kywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java
+145
-0
ci-dependencies/resin-4.0.41.jar
ci-dependencies/resin-4.0.41.jar
+0
-0
未找到文件。
.travis.yml
浏览文件 @
1c4905ef
...
...
@@ -10,6 +10,7 @@ install:
-
mvn install:install-file -Dfile=jmxri-1.2.1.jar -DgroupId=com.sun.jmx -DartifactId=jmxri -Dversion=1.2.1 -Dpackaging=jar
-
mvn install:install-file -Dfile=dubbox-2.8.4.jar -DgroupId=com.alibaba -DartifactId=dubbox -Dversion=2.8.4 -Dpackaging=jar
-
mvn install:install-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar
-
mvn install:install-file -Dfile=resin-4.0.41.jar -DgroupId=com.caucho -DartifactId=resin -Dversion=4.0.41 -Dpackaging=jar
-
cd ..
script
:
...
...
apm-sniffer/apm-agent/pom.xml
浏览文件 @
1c4905ef
...
...
@@ -60,6 +60,16 @@
<artifactId>
apm-mongodb-3.x-plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-resin-3.x-plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-resin-4.x-plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
<!-- activation -->
<dependency>
...
...
apm-sniffer/apm-sdk-plugin/pom.xml
浏览文件 @
1c4905ef
...
...
@@ -18,6 +18,8 @@
<module>
tomcat-7.x-8.x-plugin
</module>
<module>
motan-plugin
</module>
<module>
mongodb-3.x-plugin
</module>
<module>
resin-3.x-plugin
</module>
<module>
resin-4.x-plugin
</module>
</modules>
<packaging>
pom
</packaging>
...
...
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/pom.xml
0 → 100644
浏览文件 @
1c4905ef
<?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>
<artifactId>
apm-sdk-plugin
</artifactId>
<groupId>
org.skywalking
</groupId>
<version>
3.1-2017
</version>
</parent>
<artifactId>
apm-resin-3.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
resin-3.x-plugin
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
com.caucho
</groupId>
<artifactId>
resin
</artifactId>
<version>
3.0.9
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
3.0.1
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- 源码插件 -->
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/ResinV3Interceptor.java
0 → 100644
浏览文件 @
1c4905ef
package
org.skywalking.apm.plugin.resin.v3
;
import
com.caucho.server.http.HttpResponse
;
import
com.caucho.server.http.HttpRequest
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.trace.Span
;
import
org.skywalking.apm.trace.tag.Tags
;
import
org.skywalking.apm.util.StringUtil
;
/**
* {@link ResinV3Interceptor} intercept method of{@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest,
* javax.servlet.ServletResponse)} record the resin host, port ,url.
*
* @author baiyang
*/
public
class
ResinV3Interceptor
implements
InstanceMethodsAroundInterceptor
{
/**
* Header name that the serialized context data stored in
* {@link HttpRequest#getHeader(String)}.
*/
public
static
final
String
HEADER_NAME_OF_CONTEXT_DATA
=
"SWTraceContext"
;
/**
* Resin component.
*/
public
static
final
String
RESIN_COMPONENT
=
"Resin"
;
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
Object
[]
args
=
interceptorContext
.
allArguments
();
HttpRequest
request
=
(
HttpRequest
)
args
[
0
];
Span
span
=
ContextManager
.
createSpan
(
request
.
getRequestURI
());
Tags
.
COMPONENT
.
set
(
span
,
RESIN_COMPONENT
);
Tags
.
PEER_HOST
.
set
(
span
,
request
.
getServerName
());
Tags
.
PEER_PORT
.
set
(
span
,
request
.
getServerPort
());
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_SERVER
);
Tags
.
URL
.
set
(
span
,
request
.
getRequestURL
().
toString
());
Tags
.
SPAN_LAYER
.
asHttp
(
span
);
String
tracingHeaderValue
=
request
.
getHeader
(
HEADER_NAME_OF_CONTEXT_DATA
);
if
(!
StringUtil
.
isEmpty
(
tracingHeaderValue
))
{
ContextManager
.
extract
(
new
ContextCarrier
().
deserialize
(
tracingHeaderValue
));
}
}
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
HttpResponse
response
=
(
HttpResponse
)
interceptorContext
.
allArguments
()[
1
];
Span
span
=
ContextManager
.
activeSpan
();
Tags
.
STATUS_CODE
.
set
(
span
,
response
.
getStatusCode
());
if
(
response
.
getStatusCode
()
!=
200
)
{
Tags
.
ERROR
.
set
(
span
,
true
);
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
Throwable
t
,
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
)
{
Span
span
=
ContextManager
.
activeSpan
();
span
.
log
(
t
);
Tags
.
ERROR
.
set
(
span
,
true
);
}
}
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v3/define/ResinV3Instrumentation.java
0 → 100644
浏览文件 @
1c4905ef
package
org.skywalking.apm.plugin.resin.v3.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
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.plugin.resin.v3.ResinV3Interceptor
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* {@link ResinV3Instrumentation} presents that skywalking intercepts {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest,
* javax.servlet.ServletResponse)} by using {@link ResinV3Interceptor}.
*
* @author baiyang
*/
public
class
ResinV3Instrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"com.caucho.server.dispatch.ServletInvocation"
;
private
static
final
String
METHOD_INTERCET_CLASS
=
"org.skywalking.apm.plugin.resin.v3.ResinV3Interceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
null
;
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"service"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
METHOD_INTERCET_CLASS
;
}
}
};
}
@Override
protected
String
enhanceClassName
()
{
return
ENHANCE_CLASS
;
}
@Override
protected
String
[]
witnessClasses
()
{
return
new
String
[]
{
"com.caucho.server.connection.AbstractHttpResponse"
};
}
}
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
1c4905ef
resin-3.x=org.skywalking.apm.plugin.resin.v3.define.ResinV3Instrumentation
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/resin-3.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v3/ResinV3InterceptorTest.java
0 → 100644
浏览文件 @
1c4905ef
package
org.skywalking.apm.plugin.resin.v3
;
import
com.caucho.server.http.HttpResponse
;
import
com.caucho.server.http.HttpRequest
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.context.TracerContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.sniffer.mock.context.MockTracerContextListener
;
import
org.skywalking.apm.sniffer.mock.context.SegmentAssert
;
import
org.skywalking.apm.trace.LogData
;
import
org.skywalking.apm.trace.Span
;
import
org.skywalking.apm.trace.TraceSegment
;
import
org.skywalking.apm.trace.TraceSegmentRef
;
import
org.skywalking.apm.trace.tag.Tags
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* ResinInterceptorTest
*
* @author baiyang
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ResinV3InterceptorTest
{
private
ResinV3Interceptor
interceptor
;
private
MockTracerContextListener
contextListener
;
@Mock
private
HttpRequest
request
;
@Mock
private
HttpResponse
response
;
@Mock
private
EnhancedClassInstanceContext
classInstanceContext
;
@Mock
private
InstanceMethodInvokeContext
methodInvokeContext
;
@Mock
private
MethodInterceptResult
methodInterceptResult
;
@Before
public
void
setUp
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
interceptor
=
new
ResinV3Interceptor
();
contextListener
=
new
MockTracerContextListener
();
TracerContext
.
ListenerManager
.
add
(
contextListener
);
when
(
request
.
getRequestURI
()).
thenReturn
(
"/test/testRequestURL"
);
when
(
request
.
getRequestURL
()).
thenReturn
(
new
StringBuffer
(
"http://localhost:8080/test/testRequestURL"
));
when
(
response
.
getStatusCode
()).
thenReturn
(
200
);
when
(
methodInvokeContext
.
allArguments
()).
thenReturn
(
new
Object
[]
{
request
,
response
});
}
@Test
public
void
testWithoutSerializedContextData
()
{
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
methodInterceptResult
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
contextListener
.
assertSize
(
1
);
contextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertHttpSpan
(
span
);
}
});
}
@Test
public
void
testWithSerializedContextData
()
{
when
(
request
.
getHeader
(
ResinV3Interceptor
.
HEADER_NAME_OF_CONTEXT_DATA
)).
thenReturn
(
"302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123|1"
);
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
methodInterceptResult
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
contextListener
.
assertSize
(
1
);
contextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertHttpSpan
(
span
);
assertTraceSegmentRef
(
traceSegment
.
getRefs
().
get
(
0
));
}
});
}
@Test
public
void
testWithOccurException
()
{
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
methodInterceptResult
);
interceptor
.
handleMethodException
(
new
RuntimeException
(),
classInstanceContext
,
methodInvokeContext
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
contextListener
.
assertSize
(
1
);
contextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertHttpSpan
(
span
);
assertThat
(
span
.
getLogs
().
size
(),
is
(
1
));
assertSpanLog
(
span
.
getLogs
().
get
(
0
));
}
});
}
private
void
assertSpanLog
(
LogData
logData
)
{
assertThat
(
logData
.
getFields
().
size
(),
is
(
4
));
assertThat
(
logData
.
getFields
().
get
(
"event"
),
CoreMatchers
.<
Object
>
is
(
"error"
));
assertThat
(
logData
.
getFields
().
get
(
"error.kind"
),
CoreMatchers
.<
Object
>
is
(
RuntimeException
.
class
.
getName
()));
assertNull
(
logData
.
getFields
().
get
(
"message"
));
}
private
void
assertTraceSegmentRef
(
TraceSegmentRef
ref
)
{
assertThat
(
ref
.
getSpanId
(),
is
(
1
));
assertThat
(
ref
.
getTraceSegmentId
(),
is
(
"302017.1487666919810.624424584.17332.1.1"
));
}
private
void
assertHttpSpan
(
Span
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"/test/testRequestURL"
));
assertThat
(
Tags
.
COMPONENT
.
get
(
span
),
is
(
"Resin"
));
assertThat
(
Tags
.
URL
.
get
(
span
),
is
(
"http://localhost:8080/test/testRequestURL"
));
assertThat
(
Tags
.
STATUS_CODE
.
get
(
span
),
is
(
200
));
assertThat
(
Tags
.
SPAN_KIND
.
get
(
span
),
is
(
Tags
.
SPAN_KIND_SERVER
));
assertTrue
(
Tags
.
SPAN_LAYER
.
isHttp
(
span
));
}
@After
public
void
tearDown
()
throws
Exception
{
TracerContext
.
ListenerManager
.
remove
(
new
MockTracerContextListener
());
}
}
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/pom.xml
0 → 100644
浏览文件 @
1c4905ef
<?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>
<artifactId>
apm-sdk-plugin
</artifactId>
<groupId>
org.skywalking
</groupId>
<version>
3.1-2017
</version>
</parent>
<artifactId>
apm-resin-4.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
resin-4.x-plugin
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
com.caucho
</groupId>
<artifactId>
resin
</artifactId>
<version>
4.0.41
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
3.0.1
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- 源码插件 -->
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/ResinV4Interceptor.java
0 → 100644
浏览文件 @
1c4905ef
package
org.skywalking.apm.plugin.resin.v4
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.caucho.server.http.HttpRequest
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.trace.Span
;
import
org.skywalking.apm.trace.tag.Tags
;
import
org.skywalking.apm.util.StringUtil
;
/**
* Created by Baiyang on 2017/5/2.
*/
public
class
ResinV4Interceptor
implements
InstanceMethodsAroundInterceptor
{
/**
* Header name that the serialized context data stored in
* {@link HttpRequest#getHeader(String)}.
*/
public
static
final
String
HEADER_NAME_OF_CONTEXT_DATA
=
"SWTraceContext"
;
/**
* Resin component.
*/
public
static
final
String
RESIN_COMPONENT
=
"Resin"
;
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
Object
[]
args
=
interceptorContext
.
allArguments
();
HttpServletRequest
request
=
(
HttpServletRequest
)
args
[
0
];
Span
span
=
ContextManager
.
createSpan
(
request
.
getRequestURI
());
Tags
.
COMPONENT
.
set
(
span
,
RESIN_COMPONENT
);
Tags
.
PEER_HOST
.
set
(
span
,
request
.
getServerName
());
Tags
.
PEER_PORT
.
set
(
span
,
request
.
getServerPort
());
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_SERVER
);
Tags
.
URL
.
set
(
span
,
request
.
getRequestURL
().
toString
());
Tags
.
SPAN_LAYER
.
asHttp
(
span
);
String
tracingHeaderValue
=
request
.
getHeader
(
HEADER_NAME_OF_CONTEXT_DATA
);
if
(!
StringUtil
.
isEmpty
(
tracingHeaderValue
))
{
ContextManager
.
extract
(
new
ContextCarrier
().
deserialize
(
tracingHeaderValue
));
}
}
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
HttpServletResponse
response
=
(
HttpServletResponse
)
interceptorContext
.
allArguments
()[
1
];
Span
span
=
ContextManager
.
activeSpan
();
Tags
.
STATUS_CODE
.
set
(
span
,
response
.
getStatus
());
if
(
response
.
getStatus
()
!=
200
)
{
Tags
.
ERROR
.
set
(
span
,
true
);
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
Throwable
t
,
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
)
{
Span
span
=
ContextManager
.
activeSpan
();
span
.
log
(
t
);
Tags
.
ERROR
.
set
(
span
,
true
);
}
}
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/java/org/skywalking/apm/plugin/resin/v4/define/ResinV4Instrumentation.java
0 → 100644
浏览文件 @
1c4905ef
package
org.skywalking.apm.plugin.resin.v4.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
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.plugin.resin.v4.ResinV4Interceptor
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* {@link ResinV4Instrumentation} presents that skywalking intercepts {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest,
* javax.servlet.ServletResponse)} by using {@link ResinV4Interceptor}.
*
* @author baiyang
*/
public
class
ResinV4Instrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"com.caucho.server.dispatch.ServletInvocation"
;
private
static
final
String
METHOD_INTERCET_CLASS
=
"org.skywalking.apm.plugin.resin.v4.ResinV4Interceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
null
;
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"service"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
METHOD_INTERCET_CLASS
;
}
}
};
}
@Override
protected
String
enhanceClassName
()
{
return
ENHANCE_CLASS
;
}
@Override
protected
String
[]
witnessClasses
()
{
return
new
String
[]
{
"com.caucho.server.http.HttpServletResponseImpl"
};
}
}
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
1c4905ef
resin-4.x=org.skywalking.apm.plugin.resin.v4.define.ResinV4Instrumentation
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/resin-4.x-plugin/src/test/java/org/skywalking/apm/plugin/resin/v4/ResinV4InterceptorTest.java
0 → 100644
浏览文件 @
1c4905ef
package
org.skywalking.apm.plugin.resin.v4
;
import
javax.servlet.http.HttpServletRequest
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.context.TracerContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.sniffer.mock.context.MockTracerContextListener
;
import
org.skywalking.apm.sniffer.mock.context.SegmentAssert
;
import
org.skywalking.apm.trace.LogData
;
import
org.skywalking.apm.trace.Span
;
import
org.skywalking.apm.trace.TraceSegment
;
import
org.skywalking.apm.trace.TraceSegmentRef
;
import
org.skywalking.apm.trace.tag.Tags
;
import
javax.servlet.http.HttpServletResponse
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* Created by Baiyang on 2017/5/6.
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ResinV4InterceptorTest
{
private
ResinV4Interceptor
interceptor
;
private
MockTracerContextListener
contextListener
;
@Mock
private
HttpServletRequest
request
;
@Mock
private
HttpServletResponse
response
;
@Mock
private
EnhancedClassInstanceContext
classInstanceContext
;
@Mock
private
InstanceMethodInvokeContext
methodInvokeContext
;
@Mock
private
MethodInterceptResult
methodInterceptResult
;
@Before
public
void
setUp
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
interceptor
=
new
ResinV4Interceptor
();
contextListener
=
new
MockTracerContextListener
();
TracerContext
.
ListenerManager
.
add
(
contextListener
);
when
(
request
.
getRequestURI
()).
thenReturn
(
"/test/testRequestURL"
);
when
(
request
.
getRequestURL
()).
thenReturn
(
new
StringBuffer
(
"http://localhost:8080/test/testRequestURL"
));
when
(
response
.
getStatus
()).
thenReturn
(
200
);
when
(
methodInvokeContext
.
allArguments
()).
thenReturn
(
new
Object
[]
{
request
,
response
});
}
@Test
public
void
testWithoutSerializedContextData
()
{
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
methodInterceptResult
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
contextListener
.
assertSize
(
1
);
contextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertHttpSpan
(
span
);
}
});
}
@Test
public
void
testWithSerializedContextData
()
{
when
(
request
.
getHeader
(
ResinV4Interceptor
.
HEADER_NAME_OF_CONTEXT_DATA
)).
thenReturn
(
"302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123|1"
);
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
methodInterceptResult
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
contextListener
.
assertSize
(
1
);
contextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertHttpSpan
(
span
);
assertTraceSegmentRef
(
traceSegment
.
getRefs
().
get
(
0
));
}
});
}
@Test
public
void
testWithOccurException
()
{
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
methodInterceptResult
);
interceptor
.
handleMethodException
(
new
RuntimeException
(),
classInstanceContext
,
methodInvokeContext
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
contextListener
.
assertSize
(
1
);
contextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertHttpSpan
(
span
);
assertThat
(
span
.
getLogs
().
size
(),
is
(
1
));
assertSpanLog
(
span
.
getLogs
().
get
(
0
));
}
});
}
private
void
assertSpanLog
(
LogData
logData
)
{
assertThat
(
logData
.
getFields
().
size
(),
is
(
4
));
assertThat
(
logData
.
getFields
().
get
(
"event"
),
CoreMatchers
.<
Object
>
is
(
"error"
));
assertThat
(
logData
.
getFields
().
get
(
"error.kind"
),
CoreMatchers
.<
Object
>
is
(
RuntimeException
.
class
.
getName
()));
assertNull
(
logData
.
getFields
().
get
(
"message"
));
}
private
void
assertTraceSegmentRef
(
TraceSegmentRef
ref
)
{
assertThat
(
ref
.
getSpanId
(),
is
(
1
));
assertThat
(
ref
.
getTraceSegmentId
(),
is
(
"302017.1487666919810.624424584.17332.1.1"
));
}
private
void
assertHttpSpan
(
Span
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"/test/testRequestURL"
));
assertThat
(
Tags
.
COMPONENT
.
get
(
span
),
is
(
"Resin"
));
assertThat
(
Tags
.
URL
.
get
(
span
),
is
(
"http://localhost:8080/test/testRequestURL"
));
assertThat
(
Tags
.
STATUS_CODE
.
get
(
span
),
is
(
200
));
assertThat
(
Tags
.
SPAN_KIND
.
get
(
span
),
is
(
Tags
.
SPAN_KIND_SERVER
));
assertTrue
(
Tags
.
SPAN_LAYER
.
isHttp
(
span
));
}
@After
public
void
tearDown
()
throws
Exception
{
TracerContext
.
ListenerManager
.
remove
(
new
MockTracerContextListener
());
}
}
ci-dependencies/resin-4.0.41.jar
0 → 100644
浏览文件 @
1c4905ef
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录