Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
9e4026e9
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,发现更多精彩内容 >>
提交
9e4026e9
编写于
5月 17, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prototype codes of supporting leaf span
上级
c3259afa
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
162 addition
and
21 deletion
+162
-21
apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java
...pm-trace/src/main/java/org/skywalking/apm/trace/Span.java
+9
-5
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
...org/skywalking/apm/agent/core/context/ContextManager.java
+10
-2
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/LeafSpan.java
.../java/org/skywalking/apm/agent/core/context/LeafSpan.java
+108
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracerContext.java
.../org/skywalking/apm/agent/core/context/TracerContext.java
+29
-8
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/TracerContextTestCase.java
...walking/apm/agent/core/context/TracerContextTestCase.java
+6
-6
未找到文件。
apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java
浏览文件 @
9e4026e9
...
...
@@ -83,7 +83,7 @@ public class Span {
* means no parent span if this {@link TraceSegment}.
* @param operationName {@link #operationName}
*/
pr
ivate
Span
(
int
spanId
,
int
parentSpanId
,
String
operationName
)
{
pr
otected
Span
(
int
spanId
,
int
parentSpanId
,
String
operationName
)
{
this
(
spanId
,
parentSpanId
,
operationName
,
System
.
currentTimeMillis
());
}
...
...
@@ -97,7 +97,7 @@ public class Span {
* @param operationName {@link #operationName}
* @param startTime given start timestamp.
*/
pr
ivate
Span
(
int
spanId
,
int
parentSpanId
,
String
operationName
,
long
startTime
)
{
pr
otected
Span
(
int
spanId
,
int
parentSpanId
,
String
operationName
,
long
startTime
)
{
this
();
this
.
spanId
=
spanId
;
this
.
parentSpanId
=
parentSpanId
;
...
...
@@ -200,17 +200,17 @@ public class Span {
*
* @return this Span instance, for chaining
*/
public
final
Span
setTag
(
String
key
,
String
value
)
{
public
Span
setTag
(
String
key
,
String
value
)
{
tagsWithStr
.
put
(
key
,
value
);
return
this
;
}
public
final
Span
setTag
(
String
key
,
boolean
value
)
{
public
Span
setTag
(
String
key
,
boolean
value
)
{
tagsWithBool
.
put
(
key
,
value
);
return
this
;
}
public
final
Span
setTag
(
String
key
,
Integer
value
)
{
public
Span
setTag
(
String
key
,
Integer
value
)
{
tagsWithInt
.
put
(
key
,
value
);
return
this
;
}
...
...
@@ -359,6 +359,10 @@ public class Span {
return
Collections
.
unmodifiableList
(
logs
);
}
public
boolean
isLeaf
()
{
return
false
;
}
@Override
public
String
toString
()
{
return
"Span{"
+
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
浏览文件 @
9e4026e9
...
...
@@ -55,11 +55,19 @@ public class ContextManager implements TracerContextListener, BootService {
}
public
static
Span
createSpan
(
String
operationName
)
{
return
get
().
createSpan
(
operationName
);
return
get
().
createSpan
(
operationName
,
false
);
}
public
static
Span
createSpan
(
String
operationName
,
long
startTime
)
{
return
get
().
createSpan
(
operationName
,
startTime
);
return
get
().
createSpan
(
operationName
,
startTime
,
false
);
}
public
static
Span
createLeafSpan
(
String
operationName
)
{
return
get
().
createSpan
(
operationName
,
true
);
}
public
static
Span
createLeafSpan
(
String
operationName
,
long
startTime
)
{
return
get
().
createSpan
(
operationName
,
startTime
,
true
);
}
public
static
Span
activeSpan
()
{
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/LeafSpan.java
0 → 100644
浏览文件 @
9e4026e9
package
org.skywalking.apm.agent.core.context
;
import
org.skywalking.apm.trace.Span
;
import
org.skywalking.apm.trace.TraceSegment
;
/**
* LeafSpan is a special type of {@link Span}
*
* In rpc-client tracing scenario, one component could constitute by many other rpc-client.
* e.g Feign constitutes by okhttp, apache httpclient, etc.
*
* By having leaf concept, no need so many spans for single rpc call.
*
* @author wusheng
*/
public
class
LeafSpan
extends
Span
{
private
int
stackDepth
=
0
;
/**
* Create a new span, by given span id and give startTime but no parent span id,
* No parent span id means that, this Span is the first span of the {@link TraceSegment}
*
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
* @param operationName {@link #operationName}
* @param startTime given start time of span
*/
public
LeafSpan
(
int
spanId
,
String
operationName
,
long
startTime
)
{
super
(
spanId
,
-
1
,
operationName
,
startTime
);
}
/**
* Create a new span, by given span id, parent span, operationName and startTime.
* This span must belong a {@link TraceSegment}, also is a part of Distributed Trace.
*
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
* @param parentSpan {@link Span}
* @param operationName {@link #operationName}
* @param startTime given start timestamp
*/
public
LeafSpan
(
int
spanId
,
Span
parentSpan
,
String
operationName
,
long
startTime
)
{
super
(
spanId
,
parentSpan
.
getSpanId
(),
operationName
,
startTime
);
}
void
push
()
{
stackDepth
++;
}
void
pop
()
{
stackDepth
--;
}
boolean
isFinished
()
{
return
stackDepth
==
0
;
}
@Override
public
boolean
isLeaf
()
{
return
true
;
}
private
boolean
isInOwnerContext
()
{
return
stackDepth
==
1
;
}
/**
* Sets the string name for the logical operation this span represents,
* only when this is in context of the leaf span owner.
*
* @return this Span instance, for chaining
*/
@Override
public
Span
setOperationName
(
String
operationName
)
{
if
(
isInOwnerContext
())
{
super
.
setOperationName
(
operationName
);
}
return
this
;
}
/**
* Set a key:value tag on the Span,
* only when this is in context of the leaf span owner.
*
* @return this Span instance, for chaining
*/
@Override
public
final
Span
setTag
(
String
key
,
String
value
)
{
if
(
isInOwnerContext
())
{
super
.
setTag
(
key
,
value
);
}
return
this
;
}
@Override
public
final
Span
setTag
(
String
key
,
boolean
value
)
{
if
(
isInOwnerContext
())
{
super
.
setTag
(
key
,
value
);
}
return
this
;
}
@Override
public
final
Span
setTag
(
String
key
,
Integer
value
)
{
if
(
isInOwnerContext
())
{
super
.
setTag
(
key
,
value
);
}
return
this
;
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracerContext.java
浏览文件 @
9e4026e9
...
...
@@ -46,26 +46,40 @@ public final class TracerContext {
* @param operationName {@link Span#operationName}
* @return the new active span.
*/
public
Span
createSpan
(
String
operationName
)
{
return
this
.
createSpan
(
operationName
,
System
.
currentTimeMillis
());
public
Span
createSpan
(
String
operationName
,
boolean
isLeaf
)
{
return
this
.
createSpan
(
operationName
,
System
.
currentTimeMillis
()
,
isLeaf
);
}
/**
* Create a new span, as an active span, by the given operationName and startTime;
*
* @param operationName {@link Span#operationName}
* @param startTime {@link Span#startTime}
* @param startTime {@link Span#startTime}
* @param isLeaf is true, if the span is a leaf in trace tree.
* @return
*/
public
Span
createSpan
(
String
operationName
,
long
startTime
)
{
public
Span
createSpan
(
String
operationName
,
long
startTime
,
boolean
isLeaf
)
{
Span
parentSpan
=
peek
();
Span
span
;
if
(
parentSpan
==
null
)
{
span
=
new
Span
(
spanIdGenerator
++,
operationName
,
startTime
);
if
(
isLeaf
)
{
span
=
new
LeafSpan
(
spanIdGenerator
++,
operationName
,
startTime
);
}
else
{
span
=
new
Span
(
spanIdGenerator
++,
operationName
,
startTime
);
}
push
(
span
);
}
else
if
(
parentSpan
.
isLeaf
())
{
span
=
parentSpan
;
LeafSpan
leafSpan
=
(
LeafSpan
)
span
;
leafSpan
.
push
();
}
else
{
span
=
new
Span
(
spanIdGenerator
++,
parentSpan
,
operationName
,
startTime
);
if
(
isLeaf
)
{
span
=
new
LeafSpan
(
spanIdGenerator
++,
parentSpan
,
operationName
,
startTime
);
}
else
{
span
=
new
Span
(
spanIdGenerator
++,
parentSpan
,
operationName
,
startTime
);
}
push
(
span
);
}
push
(
span
);
return
span
;
}
...
...
@@ -98,6 +112,13 @@ public final class TracerContext {
public
void
stopSpan
(
Span
span
,
Long
endTime
)
{
Span
lastSpan
=
peek
();
if
(
lastSpan
.
isLeaf
())
{
LeafSpan
leafSpan
=
(
LeafSpan
)
lastSpan
;
leafSpan
.
pop
();
if
(!
leafSpan
.
isFinished
())
{
return
;
}
}
if
(
lastSpan
==
span
)
{
pop
().
finish
(
segment
,
endTime
);
}
else
{
...
...
@@ -142,7 +163,7 @@ public final class TracerContext {
* Ref this {@link ContextCarrier} to this {@link TraceSegment}
*
* @param carrier holds the snapshot, if get this {@link ContextCarrier} from remote, make sure {@link
*
ContextCarrier#deserialize(String)} called.
* ContextCarrier#deserialize(String)} called.
*/
public
void
extract
(
ContextCarrier
carrier
)
{
if
(
carrier
.
isValid
())
{
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/TracerContextTestCase.java
浏览文件 @
9e4026e9
...
...
@@ -19,7 +19,7 @@ public class TracerContextTestCase {
@Test
public
void
testSpanLifeCycle
()
{
TracerContext
context
=
new
TracerContext
();
Span
span
=
context
.
createSpan
(
"/serviceA"
);
Span
span
=
context
.
createSpan
(
"/serviceA"
,
false
);
Assert
.
assertEquals
(
span
,
context
.
activeSpan
());
...
...
@@ -35,8 +35,8 @@ public class TracerContextTestCase {
@Test
public
void
testChildOfSpan
()
{
TracerContext
context
=
new
TracerContext
();
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
);
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
,
false
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
,
false
);
Assert
.
assertEquals
(
dbSpan
,
context
.
activeSpan
());
...
...
@@ -60,8 +60,8 @@ public class TracerContextTestCase {
@Test
public
void
testInject
()
{
TracerContext
context
=
new
TracerContext
();
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
);
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
,
false
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
,
false
);
Tags
.
PEER_HOST
.
set
(
dbSpan
,
"127.0.0.1"
);
Tags
.
PEER_PORT
.
set
(
dbSpan
,
8080
);
...
...
@@ -87,7 +87,7 @@ public class TracerContextTestCase {
TracerContext
context
=
new
TracerContext
();
context
.
extract
(
carrier
);
Span
span
=
context
.
createSpan
(
"/serviceC"
);
Span
span
=
context
.
createSpan
(
"/serviceC"
,
false
);
TracerContext
.
ListenerManager
.
add
(
TestTracerContextListener
.
INSTANCE
);
final
TraceSegment
[]
finishedSegmentCarrier
=
TestTracerContextListener
.
INSTANCE
.
finishedSegmentCarrier
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录