Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
b5ff6aa1
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,发现更多精彩内容 >>
提交
b5ff6aa1
编写于
7月 11, 2017
作者:
wu-sheng
提交者:
GitHub
7月 11, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #279 from ascrutae/zhangxin/feature/suport-ot-activation
suport ot activation
上级
62981fb0
1bbf84dc
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
890 addition
and
28 deletion
+890
-28
apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java
...rg/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java
+1
-1
apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java
...alking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java
+9
-9
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
...org/skywalking/apm/agent/core/context/ContextManager.java
+1
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java
...skywalking/apm/agent/core/context/trace/AbstractSpan.java
+17
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
...ing/apm/agent/core/context/trace/AbstractTracingSpan.java
+11
-7
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java
...org/skywalking/apm/agent/core/context/trace/NoopSpan.java
+9
-0
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java
...lking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java
+2
-6
apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentRefAssert.java
...org/skywalking/apm/agent/test/tools/SegmentRefAssert.java
+21
-0
apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SpanAssert.java
.../java/org/skywalking/apm/agent/test/tools/SpanAssert.java
+4
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java
...ivation/opentracing/continuation/ActivateInterceptor.java
+27
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java
...tion/opentracing/continuation/ConstructorInterceptor.java
+12
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java
...racing/continuation/SkywalkingContinuationActivation.java
+66
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java
...entracing/span/ConstructorWithSpanBuilderInterceptor.java
+42
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java
...on/opentracing/span/ConstructorWithTracerInterceptor.java
+13
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java
...activation/opentracing/span/SkywalkingSpanActivation.java
+136
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java
...it/activation/opentracing/span/SpanFinishInterceptor.java
+31
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java
...olkit/activation/opentracing/span/SpanLogInterceptor.java
+34
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java
...ion/opentracing/span/SpanSetOperationNameInterceptor.java
+30
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java
...vation/opentracing/tracer/SkywalkingTracerActivation.java
+65
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java
...pentracing/tracer/SkywalkingTracerExtractInterceptor.java
+30
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java
...opentracing/tracer/SkywalkingTracerInjectInterceptor.java
+29
-0
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/resources/skywalking-plugin.def
...acing-activation/src/main/resources/skywalking-plugin.def
+3
-2
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
.../activation/opentracing/SkywalkingSpanActivationTest.java
+292
-0
apm-sniffer/apm-toolkit-activation/pom.xml
apm-sniffer/apm-toolkit-activation/pom.xml
+5
-0
未找到文件。
apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpan.java
浏览文件 @
b5ff6aa1
...
@@ -12,7 +12,7 @@ public class SkywalkingSpan implements Span {
...
@@ -12,7 +12,7 @@ public class SkywalkingSpan implements Span {
@NeedSnifferActivation
(
@NeedSnifferActivation
(
"1.ContextManager#createSpan (Entry,Exit,Local based on builder)."
+
"1.ContextManager#createSpan (Entry,Exit,Local based on builder)."
+
"2.set the span reference to the dynamic field of enhanced SkywalkingSpan"
)
"2.set the span reference to the dynamic field of enhanced SkywalkingSpan"
)
public
SkywalkingSpan
(
SkywalkingSpanBuilder
builder
)
{
SkywalkingSpan
(
SkywalkingSpanBuilder
builder
)
{
}
}
/**
/**
...
...
apm-application-toolkit/apm-toolkit-opentracing/src/main/java/org/skywalking/apm/toolkit/opentracing/SkywalkingSpanBuilder.java
浏览文件 @
b5ff6aa1
...
@@ -38,7 +38,7 @@ public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
...
@@ -38,7 +38,7 @@ public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
@Override
@Override
public
Tracer
.
SpanBuilder
asChildOf
(
BaseSpan
<?>
parent
)
{
public
Tracer
.
SpanBuilder
asChildOf
(
BaseSpan
<?>
parent
)
{
if
(
parent
instanceof
SkywalkingSpan
)
{
if
(
parent
instanceof
SkywalkingSpan
||
parent
instanceof
SkywalkingActiveSpan
)
{
return
this
;
return
this
;
}
}
throw
new
IllegalArgumentException
(
"parent must be type of SkywalkingSpan"
);
throw
new
IllegalArgumentException
(
"parent must be type of SkywalkingSpan"
);
...
@@ -61,23 +61,23 @@ public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
...
@@ -61,23 +61,23 @@ public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
@Override
@Override
public
Tracer
.
SpanBuilder
withTag
(
String
key
,
String
value
)
{
public
Tracer
.
SpanBuilder
withTag
(
String
key
,
String
value
)
{
if
(
Tags
.
COMPONENT
.
equals
(
key
))
{
if
(
Tags
.
COMPONENT
.
getKey
().
equals
(
key
))
{
componentName
=
value
;
componentName
=
value
;
}
else
if
(
Tags
.
SPAN_KIND
.
equals
(
key
))
{
}
else
if
(
Tags
.
SPAN_KIND
.
getKey
().
equals
(
key
))
{
if
(
Tags
.
SPAN_KIND_CLIENT
.
equals
(
key
)
||
Tags
.
SPAN_KIND_PRODUCER
.
equals
(
key
))
{
if
(
Tags
.
SPAN_KIND_CLIENT
.
equals
(
value
)
||
Tags
.
SPAN_KIND_PRODUCER
.
equals
(
value
))
{
isEntry
=
false
;
isEntry
=
false
;
isExit
=
true
;
isExit
=
true
;
}
else
if
(
Tags
.
SPAN_KIND_SERVER
.
equals
(
key
)
||
Tags
.
SPAN_KIND_CONSUMER
.
equals
(
key
))
{
}
else
if
(
Tags
.
SPAN_KIND_SERVER
.
equals
(
value
)
||
Tags
.
SPAN_KIND_CONSUMER
.
equals
(
value
))
{
isEntry
=
true
;
isEntry
=
true
;
isExit
=
false
;
isExit
=
false
;
}
else
{
}
else
{
isEntry
=
false
;
isEntry
=
false
;
isExit
=
false
;
isExit
=
false
;
}
}
}
else
if
(
Tags
.
PEER_HOST_IPV4
.
equals
(
key
)
||
Tags
.
PEER_HOST_IPV6
.
equals
(
key
)
}
else
if
(
Tags
.
PEER_HOST_IPV4
.
getKey
().
equals
(
key
)
||
Tags
.
PEER_HOST_IPV6
.
getKey
()
.
equals
(
key
)
||
Tags
.
PEER_HOSTNAME
.
equals
(
key
))
{
||
Tags
.
PEER_HOSTNAME
.
getKey
().
equals
(
key
))
{
peer
=
value
;
peer
=
value
;
}
else
if
(
Tags
.
PEER_SERVICE
.
equals
(
key
))
{
}
else
if
(
Tags
.
PEER_SERVICE
.
getKey
().
equals
(
key
))
{
operationName
=
value
;
operationName
=
value
;
}
else
{
}
else
{
tags
.
add
(
new
Tag
(
key
,
value
));
tags
.
add
(
new
Tag
(
key
,
value
));
...
@@ -97,7 +97,7 @@ public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
...
@@ -97,7 +97,7 @@ public class SkywalkingSpanBuilder implements Tracer.SpanBuilder {
@Override
@Override
public
Tracer
.
SpanBuilder
withTag
(
String
key
,
Number
value
)
{
public
Tracer
.
SpanBuilder
withTag
(
String
key
,
Number
value
)
{
if
(
Tags
.
PEER_PORT
.
equals
(
key
))
{
if
(
Tags
.
PEER_PORT
.
getKey
().
equals
(
key
))
{
port
=
value
.
intValue
();
port
=
value
.
intValue
();
}
else
{
}
else
{
tags
.
add
(
new
Tag
(
key
,
value
.
toString
()));
tags
.
add
(
new
Tag
(
key
,
value
.
toString
()));
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
浏览文件 @
b5ff6aa1
...
@@ -109,9 +109,7 @@ public class ContextManager implements TracingContextListener, BootService, Igno
...
@@ -109,9 +109,7 @@ public class ContextManager implements TracingContextListener, BootService, Igno
}
}
public
static
void
inject
(
ContextCarrier
carrier
)
{
public
static
void
inject
(
ContextCarrier
carrier
)
{
if
(
carrier
!=
null
&&
carrier
.
isValid
())
{
get
().
inject
(
carrier
);
get
().
inject
(
carrier
);
}
}
}
public
static
void
extract
(
ContextCarrier
carrier
)
{
public
static
void
extract
(
ContextCarrier
carrier
)
{
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractSpan.java
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.agent.core.context.trace
;
package
org.skywalking.apm.agent.core.context.trace
;
import
java.util.Map
;
import
org.skywalking.apm.network.trace.component.Component
;
import
org.skywalking.apm.network.trace.component.Component
;
/**
/**
...
@@ -54,4 +55,20 @@ public interface AbstractSpan {
...
@@ -54,4 +55,20 @@ public interface AbstractSpan {
* @return true if the actual span is an exit span.
* @return true if the actual span is an exit span.
*/
*/
boolean
isExit
();
boolean
isExit
();
/**
* Record an event at a specific timestamp.
*
* @param timestamp The explicit timestamp for the log record.
* @param event the events
* @return the Span, for chaining
*/
AbstractSpan
log
(
long
timestamp
,
Map
<
String
,
?>
event
);
/**
* Sets the string name for the logical operation this span represents.
*
* @return this Span instance, for chaining
*/
AbstractSpan
setOperationName
(
String
operationName
);
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
浏览文件 @
b5ff6aa1
...
@@ -87,7 +87,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -87,7 +87,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return
true
;
return
true
;
}
}
public
AbstractSpan
start
()
{
public
Abstract
Tracing
Span
start
()
{
this
.
startTime
=
System
.
currentTimeMillis
();
this
.
startTime
=
System
.
currentTimeMillis
();
return
this
;
return
this
;
}
}
...
@@ -98,7 +98,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -98,7 +98,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @param t any subclass of {@link Throwable}, which occurs in this span.
* @param t any subclass of {@link Throwable}, which occurs in this span.
* @return the Span, for chaining
* @return the Span, for chaining
*/
*/
public
AbstractSpan
log
(
Throwable
t
)
{
@Override
public
AbstractTracingSpan
log
(
Throwable
t
)
{
if
(
logs
==
null
)
{
if
(
logs
==
null
)
{
logs
=
new
LinkedList
<
LogDataEntity
>();
logs
=
new
LinkedList
<
LogDataEntity
>();
}
}
...
@@ -117,7 +118,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -117,7 +118,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @param fields
* @param fields
* @return the Span, for chaining
* @return the Span, for chaining
*/
*/
public
AbstractSpan
log
(
long
timestampMicroseconds
,
Map
<
String
,
?>
fields
)
{
@Override
public
AbstractTracingSpan
log
(
long
timestampMicroseconds
,
Map
<
String
,
?>
fields
)
{
if
(
logs
==
null
)
{
if
(
logs
==
null
)
{
logs
=
new
LinkedList
<
LogDataEntity
>();
logs
=
new
LinkedList
<
LogDataEntity
>();
}
}
...
@@ -135,7 +137,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -135,7 +137,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
*
*
* @return span instance, for chaining.
* @return span instance, for chaining.
*/
*/
public
AbstractSpan
errorOccurred
()
{
@Override
public
AbstractTracingSpan
errorOccurred
()
{
this
.
errorOccurred
=
true
;
this
.
errorOccurred
=
true
;
return
this
;
return
this
;
}
}
...
@@ -147,6 +150,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -147,6 +150,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @param operationName
* @param operationName
* @return span instance, for chaining.
* @return span instance, for chaining.
*/
*/
@Override
public
AbstractTracingSpan
setOperationName
(
String
operationName
)
{
public
AbstractTracingSpan
setOperationName
(
String
operationName
)
{
this
.
operationName
=
operationName
;
this
.
operationName
=
operationName
;
return
this
;
return
this
;
...
@@ -176,7 +180,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -176,7 +180,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
}
}
@Override
@Override
public
AbstractSpan
setLayer
(
SpanLayer
layer
)
{
public
Abstract
Tracing
Span
setLayer
(
SpanLayer
layer
)
{
this
.
layer
=
layer
;
this
.
layer
=
layer
;
return
this
;
return
this
;
}
}
...
@@ -189,7 +193,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -189,7 +193,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @return span instance, for chaining.
* @return span instance, for chaining.
*/
*/
@Override
@Override
public
AbstractSpan
setComponent
(
Component
component
)
{
public
Abstract
Tracing
Span
setComponent
(
Component
component
)
{
this
.
componentId
=
component
.
getId
();
this
.
componentId
=
component
.
getId
();
return
this
;
return
this
;
}
}
...
@@ -202,7 +206,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
...
@@ -202,7 +206,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @return span instance, for chaining.
* @return span instance, for chaining.
*/
*/
@Override
@Override
public
AbstractSpan
setComponent
(
String
componentName
)
{
public
Abstract
Tracing
Span
setComponent
(
String
componentName
)
{
this
.
componentName
=
componentName
;
this
.
componentName
=
componentName
;
return
this
;
return
this
;
}
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/NoopSpan.java
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.agent.core.context.trace
;
package
org.skywalking.apm.agent.core.context.trace
;
import
java.util.Map
;
import
org.skywalking.apm.agent.core.context.IgnoredTracerContext
;
import
org.skywalking.apm.agent.core.context.IgnoredTracerContext
;
import
org.skywalking.apm.network.trace.component.Component
;
import
org.skywalking.apm.network.trace.component.Component
;
...
@@ -51,4 +52,12 @@ public class NoopSpan implements AbstractSpan {
...
@@ -51,4 +52,12 @@ public class NoopSpan implements AbstractSpan {
@Override
public
boolean
isExit
()
{
@Override
public
boolean
isExit
()
{
return
false
;
return
false
;
}
}
@Override
public
AbstractSpan
log
(
long
timestamp
,
Map
<
String
,
?>
event
)
{
return
this
;
}
@Override
public
AbstractSpan
setOperationName
(
String
operationName
)
{
return
this
;
}
}
}
apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v3/MongoDBMethodInterceptor.java
浏览文件 @
b5ff6aa1
...
@@ -50,11 +50,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
...
@@ -50,11 +50,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
*/
*/
public
class
MongoDBMethodInterceptor
implements
InstanceMethodsAroundInterceptor
,
InstanceConstructorInterceptor
{
public
class
MongoDBMethodInterceptor
implements
InstanceMethodsAroundInterceptor
,
InstanceConstructorInterceptor
{
static
final
String
MONGODB_HOST
=
"MONGODB_HOST"
;
private
static
final
String
DB_TYPE
=
"MongoDB"
;
static
final
String
MONGODB_PORT
=
"MONGODB_PORT"
;
private
static
final
String
MONGODB_COMPONENT
=
"MongoDB"
;
private
static
final
String
METHOD
=
"MongoDB/"
;
private
static
final
String
METHOD
=
"MongoDB/"
;
...
@@ -159,7 +155,7 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
...
@@ -159,7 +155,7 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
String
remotePeer
=
(
String
)
objInst
.
getSkyWalkingDynamicField
();
String
remotePeer
=
(
String
)
objInst
.
getSkyWalkingDynamicField
();
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
METHOD
+
methodName
,
new
ContextCarrier
(),
remotePeer
);
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
METHOD
+
methodName
,
new
ContextCarrier
(),
remotePeer
);
span
.
setComponent
(
ComponentsDefine
.
MONGODB
);
span
.
setComponent
(
ComponentsDefine
.
MONGODB
);
Tags
.
DB_TYPE
.
set
(
span
,
MONGODB_COMPONENT
);
Tags
.
DB_TYPE
.
set
(
span
,
DB_TYPE
);
SpanLayer
.
asDB
(
span
);
SpanLayer
.
asDB
(
span
);
if
(
Config
.
Plugin
.
MongoDB
.
TRACE_PARAM
)
{
if
(
Config
.
Plugin
.
MongoDB
.
TRACE_PARAM
)
{
...
...
apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SegmentRefAssert.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.agent.test.tools
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegmentRef
;
import
org.skywalking.apm.agent.test.helper.SegmentRefHelper
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
public
class
SegmentRefAssert
{
public
static
void
assertSegmentId
(
TraceSegmentRef
ref
,
String
segmentId
)
{
assertThat
(
SegmentRefHelper
.
getTraceSegmentId
(
ref
),
is
(
segmentId
));
}
public
static
void
assertSpanId
(
TraceSegmentRef
ref
,
int
spanId
)
{
assertThat
(
SegmentRefHelper
.
getSpanId
(
ref
),
is
(
spanId
));
}
public
static
void
assertPeerHost
(
TraceSegmentRef
ref
,
String
peerHost
)
{
assertThat
(
SegmentRefHelper
.
getPeerHost
(
ref
),
is
(
peerHost
));
}
}
apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/tools/SpanAssert.java
浏览文件 @
b5ff6aa1
...
@@ -38,6 +38,10 @@ public class SpanAssert {
...
@@ -38,6 +38,10 @@ public class SpanAssert {
assertThat
(
SpanHelper
.
getComponentId
(
span
),
is
(
component
.
getId
()));
assertThat
(
SpanHelper
.
getComponentId
(
span
),
is
(
component
.
getId
()));
}
}
public
static
void
assertComponent
(
AbstractSpan
span
,
String
componentName
)
{
assertThat
(
SpanHelper
.
getComponentName
(
span
),
is
(
componentName
));
}
public
static
void
assertLayer
(
AbstractSpan
span
,
SpanLayer
spanLayer
)
{
public
static
void
assertLayer
(
AbstractSpan
span
,
SpanLayer
spanLayer
)
{
assertThat
(
SpanHelper
.
getLayer
(
span
),
is
(
spanLayer
));
assertThat
(
SpanHelper
.
getLayer
(
span
),
is
(
spanLayer
));
}
}
...
...
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ActivateInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.continuation
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.ContextSnapshot
;
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
ActivateInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Object
contextSnapshot
=
objInst
.
getSkyWalkingDynamicField
();
if
(
contextSnapshot
!=
null
)
{
ContextManager
.
continued
((
ContextSnapshot
)
contextSnapshot
);
}
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/ConstructorInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.continuation
;
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.InstanceConstructorInterceptor
;
public
class
ConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
objInst
.
setSkyWalkingDynamicField
(
ContextManager
.
capture
());
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/continuation/SkywalkingContinuationActivation.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.continuation
;
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
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* {@link SkywalkingContinuationActivation} defines two interceptors to enhance the methods and constructor in class
* <code>org.skywalking.apm.toolkit.opentracing.SkywalkingContinuation</code>.
*
* 1. The <code>org.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor</code>
* interceptor enhance the constructor.
*
* 2. The <code>org.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor</code>
* interceptor enhance the <code>activate</code>.
*/
public
class
SkywalkingContinuationActivation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.skywalking.apm.toolkit.opentracing.SkywalkingContinuation"
;
private
static
final
String
CONSTRUCTOR_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor"
;
private
static
final
String
ACTIVATE_METHOD_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor"
;
@Override
protected
String
enhanceClassName
()
{
return
ENHANCE_CLASS
;
}
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
CONSTRUCTOR_INTERCEPTOR
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"activate"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
ACTIVATE_METHOD_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.span
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder
;
import
org.skywalking.apm.toolkit.opentracing.Tag
;
import
org.skywalking.apm.util.StringUtil
;
public
class
ConstructorWithSpanBuilderInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
SkywalkingSpanBuilder
spanBuilder
=
(
SkywalkingSpanBuilder
)
allArguments
[
0
];
AbstractSpan
span
;
if
(
spanBuilder
.
isEntry
())
{
span
=
ContextManager
.
createEntrySpan
(
spanBuilder
.
getOperationName
(),
null
);
}
else
if
(
spanBuilder
.
isExit
()
&&
(!
StringUtil
.
isEmpty
(
spanBuilder
.
getPeer
())))
{
span
=
ContextManager
.
createExitSpan
(
spanBuilder
.
getOperationName
(),
new
ContextCarrier
(),
buildRemotePeer
(
spanBuilder
));
}
else
{
span
=
ContextManager
.
createLocalSpan
(
spanBuilder
.
getOperationName
());
}
for
(
Tag
tag
:
spanBuilder
.
getTags
())
{
span
.
tag
(
tag
.
getKey
(),
tag
.
getValue
());
}
span
.
setComponent
(
spanBuilder
.
getComponentName
());
if
(
spanBuilder
.
isError
())
{
span
.
errorOccurred
();
}
objInst
.
setSkyWalkingDynamicField
(
span
);
}
private
String
buildRemotePeer
(
SkywalkingSpanBuilder
spanBuilder
)
{
return
spanBuilder
.
getPeer
()
+
(
spanBuilder
.
getPort
()
==
0
?
""
:
":"
+
spanBuilder
.
getPort
());
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithTracerInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.span
;
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.InstanceConstructorInterceptor
;
public
class
ConstructorWithTracerInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
objInst
.
setSkyWalkingDynamicField
(
ContextManager
.
activeSpan
());
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SkywalkingSpanActivation.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.span
;
import
java.util.Map
;
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
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
takesArgument
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
bytebuddy
.
ArgumentTypeNameMatch
.
takesArgumentWithType
;
/**
* {@link SkywalkingSpanActivation} defines five interceptors to enhance the methods and constructor in class
* <code>org.skywalking.apm.toolkit.opentracing.SkywalkingSpan</code>.
*
* 1. The <code>org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor</code>
* interceptor enhance the constructor with <code>org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder</code>
* argument.
*
* 2. The <code>org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithTracerInterceptor</code>
* interceptor enhance the constructor with <code>org.skywalking.apm.toolkit.opentracing.SkywalkingTracer</code>
* argument.
*
* 3. The <code>org.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor</code>
* interceptor enhance the <code>finish</code> method that the first argument type is {@link Long}
*
* 4. The <code>org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor</code>
* interceptor enhance the <code>log</code> method that the first argument type is {@link Long} and the second
* argument type is {@link Map<String,?>}
*
* 5. The <code>org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor</code>
* interceptor enhance the <code>setOperationName</code> method
**/
public
class
SkywalkingSpanActivation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.skywalking.apm.toolkit.opentracing.SkywalkingSpan"
;
private
static
final
String
SPAN_BUILDER_CLASS_NAME
=
"org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder"
;
private
static
final
String
CONSTRUCTOR_WITH_SPAN_BUILDER_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor"
;
private
static
final
String
SKYWALKING_TRACER_CLASS_NAME
=
"org.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
;
private
static
final
String
CONSTRUCTOR_WITH_TRACER_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithTracerInterceptor"
;
private
static
final
String
FINISH_METHOD_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor"
;
private
static
final
String
LOG_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor"
;
private
static
final
String
SET_OPERATION_NAME_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor"
;
@Override
protected
String
enhanceClassName
()
{
return
ENHANCE_CLASS
;
}
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
takesArgumentWithType
(
0
,
SPAN_BUILDER_CLASS_NAME
);
}
@Override
public
String
getConstructorInterceptor
()
{
return
CONSTRUCTOR_WITH_SPAN_BUILDER_INTERCEPTOR
;
}
},
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
takesArgumentWithType
(
0
,
SKYWALKING_TRACER_CLASS_NAME
);
}
@Override
public
String
getConstructorInterceptor
()
{
return
CONSTRUCTOR_WITH_TRACER_INTERCEPTOR
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"finish"
).
and
(
takesArgument
(
0
,
long
.
class
));
}
@Override
public
String
getMethodsInterceptor
()
{
return
FINISH_METHOD_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"log"
).
and
(
takesArgument
(
0
,
long
.
class
).
and
(
takesArgument
(
1
,
Map
.
class
)));
}
@Override
public
String
getMethodsInterceptor
()
{
return
LOG_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"setOperationName"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
SET_OPERATION_NAME_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanFinishInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.span
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
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
SpanFinishInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
AbstractSpan
abstractSpan
=
(
AbstractSpan
)
objInst
.
getSkyWalkingDynamicField
();
if
(
abstractSpan
!=
null
)
{
ContextManager
.
stopSpan
(
abstractSpan
);
}
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanLogInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.span
;
import
java.util.Map
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
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
;
/**
* Created by xin on 2017/7/10.
*/
public
class
SpanLogInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
AbstractSpan
abstractSpan
=
(
AbstractSpan
)
objInst
.
getSkyWalkingDynamicField
();
if
(
abstractSpan
!=
null
)
{
abstractSpan
.
log
(
Long
.
parseLong
(
allArguments
[
0
].
toString
()),
(
Map
<
String
,
?>)
allArguments
[
1
]);
}
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/span/SpanSetOperationNameInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.span
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
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
SpanSetOperationNameInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
AbstractSpan
tracingSpan
=
(
AbstractSpan
)
objInst
.
getSkyWalkingDynamicField
();
if
(
tracingSpan
!=
null
)
{
tracingSpan
.
setOperationName
(
allArguments
[
0
].
toString
());
}
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerActivation.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.tracer
;
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
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* {@link SkywalkingTracerActivation} defines two interceptors to enhance the methods in
* class <code>org.skywalking.apm.toolkit.opentracing.SkywalkingTracer</code>.
*
* 1. The <code>org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor</code>
* interceptor enhance the <code>extract</code> method
*
* 2. The <code>org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor</code>
* interceptor enhance the <code>inject</code> method
**/
public
class
SkywalkingTracerActivation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
;
private
static
final
String
INJECT_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor"
;
private
static
final
String
EXTRACT_INTERCEPTOR
=
"org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor"
;
@Override
protected
String
enhanceClassName
()
{
return
ENHANCE_CLASS
;
}
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"inject"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
INJECT_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"extract"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
EXTRACT_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerExtractInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.tracer
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
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
SkywalkingTracerExtractInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
String
carrier
=
(
String
)
allArguments
[
0
];
ContextCarrier
contextCarrier
=
new
ContextCarrier
().
deserialize
(
carrier
);
ContextManager
.
extract
(
contextCarrier
);
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/skywalking/apm/toolkit/activation/opentracing/tracer/SkywalkingTracerInjectInterceptor.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing.tracer
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
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
SkywalkingTracerInjectInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
ContextManager
.
inject
(
contextCarrier
);
return
contextCarrier
.
serialize
();
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
String
methodName
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/resources/skywalking-plugin.def
浏览文件 @
b5ff6aa1
opentracing=org.skywalking.apm.toolkit.activation.opentracing.span.SkyWalkingSpanActivation
opentracing=org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerActivation
opentracing=org.skywalking.apm.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
opentracing=org.skywalking.apm.toolkit.activation.opentracing.span.SkywalkingSpanActivation
\ No newline at end of file
opentracing=org.skywalking.apm.toolkit.activation.opentracing.continuation.SkywalkingContinuationActivation
apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
0 → 100644
浏览文件 @
b5ff6aa1
package
org.skywalking.apm.toolkit.activation.opentracing
;
import
io.opentracing.Tracer
;
import
io.opentracing.tag.Tags
;
import
java.util.HashMap
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextSnapshot
;
import
org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegmentRef
;
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
;
import
org.skywalking.apm.toolkit.activation.opentracing.continuation.ActivateInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.continuation.ConstructorInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.span.ConstructorWithSpanBuilderInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.span.SpanFinishInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.span.SpanLogInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.span.SpanSetOperationNameInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerExtractInterceptor
;
import
org.skywalking.apm.toolkit.activation.opentracing.tracer.SkywalkingTracerInjectInterceptor
;
import
org.skywalking.apm.toolkit.opentracing.SkywalkingSpanBuilder
;
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
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SegmentRefAssert
.
assertPeerHost
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SegmentRefAssert
.
assertSegmentId
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SegmentRefAssert
.
assertSpanId
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertComponent
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertLogSize
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
SkywalkingSpanActivationTest
{
@SegmentStoragePoint
private
SegmentStorage
storage
;
@Rule
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
private
MockEnhancedInstance
enhancedInstance
=
new
MockEnhancedInstance
();
private
ConstructorWithSpanBuilderInterceptor
constructorWithSpanBuilderInterceptor
;
private
Tracer
.
SpanBuilder
spanBuilder
=
new
SkywalkingSpanBuilder
(
"test"
);
private
SpanLogInterceptor
spanLogInterceptor
;
private
Object
[]
logArgument
;
private
HashMap
<
String
,
Object
>
event
=
new
HashMap
<
String
,
Object
>()
{
{
put
(
"a"
,
"A"
);
}
};
private
Class
[]
logArgumentType
;
private
SpanSetOperationNameInterceptor
setOperationNameInterceptor
;
private
Object
[]
setOperationNameArgument
;
private
Class
[]
setOperationNameArgumentType
;
private
SpanFinishInterceptor
spanFinishInterceptor
;
private
SkywalkingTracerInjectInterceptor
injectInterceptor
;
private
SkywalkingTracerExtractInterceptor
extractInterceptor
;
private
ConstructorInterceptor
constructorInterceptor
;
private
ActivateInterceptor
activateInterceptor
;
@Before
public
void
setUp
()
{
spanBuilder
=
new
SkywalkingSpanBuilder
(
"test"
).
withTag
(
Tags
.
COMPONENT
.
getKey
(),
"test"
);
constructorWithSpanBuilderInterceptor
=
new
ConstructorWithSpanBuilderInterceptor
();
spanLogInterceptor
=
new
SpanLogInterceptor
();
logArgument
=
new
Object
[]
{
111111111L
,
event
};
logArgumentType
=
new
Class
[]
{
long
.
class
,
HashMap
.
class
};
setOperationNameInterceptor
=
new
SpanSetOperationNameInterceptor
();
setOperationNameArgument
=
new
Object
[]
{
"testOperationName"
};
setOperationNameArgumentType
=
new
Class
[]
{
String
.
class
};
spanFinishInterceptor
=
new
SpanFinishInterceptor
();
injectInterceptor
=
new
SkywalkingTracerInjectInterceptor
();
extractInterceptor
=
new
SkywalkingTracerExtractInterceptor
();
constructorInterceptor
=
new
ConstructorInterceptor
();
activateInterceptor
=
new
ActivateInterceptor
();
}
@Test
public
void
testCreateLocalSpan
()
throws
Throwable
{
startSpan
();
stopSpan
();
TraceSegment
tracingSegment
=
assertTraceSemgnets
();
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
tracingSegment
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertThat
(
spans
.
get
(
0
).
isEntry
(),
is
(
false
));
assertThat
(
spans
.
get
(
0
).
isExit
(),
is
(
false
));
}
@Test
public
void
testCreateEntrySpan
()
throws
Throwable
{
spanBuilder
.
withTag
(
Tags
.
SPAN_KIND
.
getKey
(),
Tags
.
SPAN_KIND_SERVER
);
startSpan
();
stopSpan
();
TraceSegment
tracingSegment
=
assertTraceSemgnets
();
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
tracingSegment
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertSpanCommonsAttribute
(
spans
.
get
(
0
));
assertThat
(
spans
.
get
(
0
).
isEntry
(),
is
(
true
));
}
@Test
public
void
testCreateExitSpanWithoutPeer
()
throws
Throwable
{
spanBuilder
.
withTag
(
Tags
.
SPAN_KIND
.
getKey
(),
Tags
.
SPAN_KIND_CLIENT
);
startSpan
();
stopSpan
();
TraceSegment
tracingSegment
=
assertTraceSemgnets
();
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
tracingSegment
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertSpanCommonsAttribute
(
spans
.
get
(
0
));
assertThat
(
spans
.
get
(
0
).
isEntry
(),
is
(
false
));
assertThat
(
spans
.
get
(
0
).
isExit
(),
is
(
false
));
}
@Test
public
void
testCreateExitSpanWithPeer
()
throws
Throwable
{
spanBuilder
.
withTag
(
Tags
.
SPAN_KIND
.
getKey
(),
Tags
.
SPAN_KIND_CLIENT
)
.
withTag
(
Tags
.
PEER_HOST_IPV4
.
getKey
(),
"127.0.0.1"
).
withTag
(
Tags
.
PEER_PORT
.
getKey
(),
"8080"
);
startSpan
();
stopSpan
();
TraceSegment
tracingSegment
=
assertTraceSemgnets
();
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
tracingSegment
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertSpanCommonsAttribute
(
spans
.
get
(
0
));
assertThat
(
spans
.
get
(
0
).
isEntry
(),
is
(
false
));
assertThat
(
spans
.
get
(
0
).
isExit
(),
is
(
true
));
}
private
TraceSegment
assertTraceSemgnets
()
{
List
<
TraceSegment
>
segments
=
storage
.
getTraceSegments
();
assertThat
(
segments
.
size
(),
is
(
1
));
return
segments
.
get
(
0
);
}
@Test
public
void
testInject
()
throws
Throwable
{
spanBuilder
.
withTag
(
Tags
.
SPAN_KIND
.
getKey
(),
Tags
.
SPAN_KIND_CLIENT
)
.
withTag
(
Tags
.
PEER_HOST_IPV4
.
getKey
(),
"127.0.0.1"
).
withTag
(
Tags
.
PEER_PORT
.
getKey
(),
8080
);
startSpan
();
String
extractValue
=
(
String
)
injectInterceptor
.
afterMethod
(
enhancedInstance
,
"extract"
,
null
,
null
,
null
);
ContextCarrier
contextCarrier
=
new
ContextCarrier
().
deserialize
(
extractValue
);
assertTrue
(
contextCarrier
.
isValid
());
assertThat
(
contextCarrier
.
getPeerHost
(),
is
(
"#127.0.0.1:8080"
));
assertThat
(
contextCarrier
.
getSpanId
(),
is
(
0
));
assertThat
(
contextCarrier
.
getEntryOperationName
(),
is
(
"#testOperationName"
));
stopSpan
();
}
@Test
public
void
testExtractWithValidateContext
()
throws
Throwable
{
spanBuilder
.
withTag
(
Tags
.
SPAN_KIND
.
getKey
(),
Tags
.
SPAN_KIND_CLIENT
)
.
withTag
(
Tags
.
PEER_HOST_IPV4
.
getKey
(),
"127.0.0.1"
).
withTag
(
Tags
.
PEER_PORT
.
getKey
(),
8080
);
startSpan
();
extractInterceptor
.
afterMethod
(
enhancedInstance
,
"extract"
,
new
Object
[]
{
"S.1499746282749.1100157028.88023.1.1|0|1|#127.0.0.1:8080|#testOperationName|T.1499746282768.1100157028.88023.1.2"
},
new
Class
[]
{
String
.
class
},
null
);
stopSpan
();
TraceSegment
tracingSegment
=
assertTraceSemgnets
();
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
tracingSegment
);
assertThat
(
tracingSegment
.
getRefs
().
size
(),
is
(
1
));
TraceSegmentRef
ref
=
tracingSegment
.
getRefs
().
get
(
0
);
assertSegmentId
(
ref
,
"S.1499746282749.1100157028.88023.1.1"
);
assertSpanId
(
ref
,
0
);
assertPeerHost
(
ref
,
"127.0.0.1:8080"
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertSpanCommonsAttribute
(
spans
.
get
(
0
));
}
@Test
public
void
testExtractWithInValidateContext
()
throws
Throwable
{
spanBuilder
.
withTag
(
Tags
.
SPAN_KIND
.
getKey
(),
Tags
.
SPAN_KIND_CLIENT
)
.
withTag
(
Tags
.
PEER_HOST_IPV4
.
getKey
(),
"127.0.0.1"
).
withTag
(
Tags
.
PEER_PORT
.
getKey
(),
8080
);
startSpan
();
extractInterceptor
.
afterMethod
(
enhancedInstance
,
"extract"
,
new
Object
[]
{
"S.1499746282749.1100157028.88023.1.1|0|1|#127.0.0.1:8080|#testOperationName"
},
new
Class
[]
{
String
.
class
},
null
);
stopSpan
();
TraceSegment
tracingSegment
=
assertTraceSemgnets
();
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
tracingSegment
);
assertNull
(
tracingSegment
.
getRefs
());
assertSpanCommonsAttribute
(
spans
.
get
(
0
));
}
@Test
public
void
testContinuation
()
throws
Throwable
{
startSpan
();
final
MockEnhancedInstance
continuationHolder
=
new
MockEnhancedInstance
();
constructorInterceptor
.
onConstruct
(
continuationHolder
,
null
);
assertTrue
(
continuationHolder
.
getSkyWalkingDynamicField
()
instanceof
ContextSnapshot
);
new
Thread
()
{
@Override
public
void
run
()
{
MockEnhancedInstance
enhancedInstance
=
new
MockEnhancedInstance
();
try
{
startSpan
(
enhancedInstance
);
activateInterceptor
.
afterMethod
(
continuationHolder
,
"activate"
,
null
,
null
,
null
);
}
catch
(
Throwable
throwable
)
{
throwable
.
printStackTrace
();
}
finally
{
try
{
stopSpan
(
enhancedInstance
);
}
catch
(
Throwable
throwable
)
{
throwable
.
printStackTrace
();
}
}
}
}.
start
();
Thread
.
sleep
(
1000L
);
stopSpan
();
List
<
TraceSegment
>
segments
=
storage
.
getTraceSegments
();
assertThat
(
segments
.
size
(),
is
(
2
));
TraceSegment
traceSegment
=
segments
.
get
(
0
);
assertThat
(
traceSegment
.
getRefs
().
size
(),
is
(
1
));
traceSegment
=
segments
.
get
(
1
);
assertNull
(
traceSegment
.
getRefs
());
}
private
void
assertSpanCommonsAttribute
(
AbstractTracingSpan
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"testOperationName"
));
assertComponent
(
span
,
"test"
);
assertLogSize
(
span
,
1
);
}
private
void
stopSpan
()
throws
Throwable
{
stopSpan
(
enhancedInstance
);
}
private
void
stopSpan
(
EnhancedInstance
enhancedInstance
)
throws
Throwable
{
spanFinishInterceptor
.
afterMethod
(
enhancedInstance
,
"finish"
,
null
,
null
,
null
);
}
private
void
startSpan
()
throws
Throwable
{
startSpan
(
enhancedInstance
);
}
private
void
startSpan
(
MockEnhancedInstance
enhancedInstance
)
throws
Throwable
{
constructorWithSpanBuilderInterceptor
.
onConstruct
(
enhancedInstance
,
new
Object
[]
{
spanBuilder
});
spanLogInterceptor
.
afterMethod
(
enhancedInstance
,
"log"
,
logArgument
,
logArgumentType
,
null
);
setOperationNameInterceptor
.
afterMethod
(
enhancedInstance
,
"setOperationName"
,
setOperationNameArgument
,
setOperationNameArgumentType
,
null
);
}
private
class
MockEnhancedInstance
implements
EnhancedInstance
{
public
Object
object
;
@Override
public
Object
getSkyWalkingDynamicField
()
{
return
object
;
}
@Override
public
void
setSkyWalkingDynamicField
(
Object
value
)
{
this
.
object
=
value
;
}
}
private
class
MockContinuationThread
extends
Thread
{
@Override
public
void
run
()
{
super
.
run
();
}
}
}
apm-sniffer/apm-toolkit-activation/pom.xml
浏览文件 @
b5ff6aa1
...
@@ -25,5 +25,10 @@
...
@@ -25,5 +25,10 @@
<artifactId>
apm-agent-core
</artifactId>
<artifactId>
apm-agent-core
</artifactId>
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-test-tools
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录