Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
9b5cd7ac
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b5cd7ac
编写于
2月 17, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Release a prototype of Span
上级
1326f545
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
191 addition
and
2 deletion
+191
-2
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/LogData.java
...ace/src/main/java/com/a/eye/skywalking/trace/LogData.java
+18
-0
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java
...-trace/src/main/java/com/a/eye/skywalking/trace/Span.java
+153
-0
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java
...rc/main/java/com/a/eye/skywalking/trace/TraceSegment.java
+20
-2
未找到文件。
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/LogData.java
0 → 100644
浏览文件 @
9b5cd7ac
package
com.a.eye.skywalking.trace
;
import
java.util.Map
;
/**
* It is a holder of one log record.
*
* Created by wusheng on 2017/2/17.
*/
public
class
LogData
{
private
final
long
time
;
private
final
Map
<
String
,
?>
fields
;
LogData
(
long
time
,
Map
<
String
,
?>
fields
)
{
this
.
time
=
time
;
this
.
fields
=
fields
;
}
}
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java
浏览文件 @
9b5cd7ac
package
com.a.eye.skywalking.trace
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* Span is a concept from OpenTracing Spec, also from Google Dapper Paper.
* Traces in OpenTracing are defined implicitly by their Spans.
...
...
@@ -21,4 +27,151 @@ package com.a.eye.skywalking.trace;
* Created by wusheng on 2017/2/17.
*/
public
class
Span
{
private
int
spanId
;
private
int
parentSpanId
;
/**
* The start time of this Span.
*/
private
long
startTime
;
/**
* The end time of this Span.
*/
private
long
endTime
;
/**
* The operation name ot this Span.
* If you want to know, how to set an operation name,
* {@see https://github.com/opentracing/specification/blob/master/specification.md#start-a-new-span}
*/
private
String
operationName
;
/**
* Tag is a concept from OpenTracing spec.
*
* {@see https://github.com/opentracing/specification/blob/master/specification.md#set-a-span-tag}
*/
private
final
Map
<
String
,
Object
>
tags
=
new
HashMap
<
String
,
Object
>();
/**
* Log is a concept from OpenTracing spec.
*
* {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data}
*/
private
final
List
<
LogData
>
logs
=
new
ArrayList
<
LogData
>();
/**
* Create a new span, by given span id and parent span id.
* 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 parentSpanId given by the creator, and must be an existed span id in the {@link TraceSegment}.
* Value -1 means no parent span if this {@link TraceSegment}.
* @param operationName {@link #operationName}
*/
public
Span
(
int
spanId
,
int
parentSpanId
,
String
operationName
){
this
.
spanId
=
spanId
;
this
.
parentSpanId
=
parentSpanId
;
this
.
startTime
=
System
.
currentTimeMillis
();
}
/**
* Create a new span, by given span id and 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}
*/
public
Span
(
int
spanId
,
String
operationName
){
this
(
spanId
,
-
1
,
operationName
);
}
/**
* Finish the active Span.
* When it is finished, it will be archived by the given {@link TraceSegment}, which owners it.
*
* @param owner of the Span.
*/
public
void
finish
(
TraceSegment
owner
){
this
.
endTime
=
System
.
currentTimeMillis
();
owner
.
archive
(
this
);
}
/**
* Set a key:value tag on the Span.
*/
public
final
Span
setTag
(
String
key
,
String
value
)
{
tags
.
put
(
key
,
value
);
return
this
;
}
public
final
Span
setTag
(
String
key
,
boolean
value
)
{
tags
.
put
(
key
,
value
);
return
this
;
}
public
final
Span
setTag
(
String
key
,
Number
value
)
{
tags
.
put
(
key
,
value
);
return
this
;
}
/**
* Get all tags from this span, but readonly.
*
* @return
*/
public
final
Map
<
String
,
Object
>
getTags
()
{
return
Collections
.
unmodifiableMap
(
tags
);
}
/**
* This method is from opentracing-java.
* {@see https://github.com/opentracing/opentracing-java/blob/release-0.20.9/opentracing-api/src/main/java/io/opentracing/Span.java#L91}
*
* Log key:value pairs to the Span with the current walltime timestamp.
*
* <p><strong>CAUTIONARY NOTE:</strong> not all Tracer implementations support key:value log fields end-to-end.
* Caveat emptor.
*
* <p>A contrived example (using Guava, which is not required):
* <pre>{@code
span.log(
ImmutableMap.Builder<String, Object>()
.put("event", "soft error")
.put("type", "cache timeout")
.put("waited.millis", 1500)
.build());
}</pre>
*
* @param fields key:value log fields. Tracer implementations should support String, numeric, and boolean values;
* some may also support arbitrary Objects.
* @return the Span, for chaining
* @see Span#log(String)
*/
Span
log
(
Map
<
String
,
?>
fields
){
logs
.
add
(
new
LogData
(
System
.
currentTimeMillis
(),
fields
));
return
this
;
}
/**
* This method is from opentracing-java.
* {@see https://github.com/opentracing/opentracing-java/blob/release-0.20.9/opentracing-api/src/main/java/io/opentracing/Span.java#L120}
*
* Record an event at the current walltime timestamp.
*
* Shorthand for
*
* <pre>{@code
span.log(Collections.singletonMap("event", event));
}</pre>
*
* @param event the event value; often a stable identifier for a moment in the Span lifecycle
* @return the Span, for chaining
*/
Span
log
(
String
event
){
log
(
Collections
.
singletonMap
(
"event"
,
event
));
return
this
;
}
}
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java
浏览文件 @
9b5cd7ac
...
...
@@ -52,17 +52,18 @@ public class TraceSegment {
/**
* Create a trace segment, by given segmentId.
* This segmentId is generated by TraceSegmentRef, AKA tracer/agent module.
* This segmentId is generated by TraceSegmentRef, AKA
, from
tracer/agent module.
*
* @param segmentId {@link #traceSegmentId}
*/
public
TraceSegment
(
String
segmentId
)
{
this
.
traceSegmentId
=
segmentId
;
this
.
startTime
=
System
.
currentTimeMillis
();
this
.
spans
=
new
LinkedList
<
Span
>();
}
/**
* Establish the link between this segment
to hi
s parents.
* Establish the link between this segment
and it
s parents.
* The first time, you {@link #ref(TraceSegmentRef)} to parent, it is affirmed as {@link #primaryRef}.
* And others are affirmed as {@link #refs}.
*
...
...
@@ -78,4 +79,21 @@ public class TraceSegment {
refs
.
add
(
refSegment
);
}
}
/**
* After {@link Span} is finished, as be controller by "skywalking-api" module,
* notify the {@link TraceSegment} to archive it.
*
* @param finishedSpan
*/
void
archive
(
Span
finishedSpan
){
spans
.
add
(
finishedSpan
);
}
/**
* Finish this {@link TraceSegment}.
*/
public
void
finish
(){
this
.
endTime
=
System
.
currentTimeMillis
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录