Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
javalover123888
SkyWalking
提交
8ec5d16d
S
SkyWalking
项目概览
javalover123888
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
2
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,发现更多精彩内容 >>
提交
8ec5d16d
编写于
12月 22, 2015
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.增加部分忽略业务异常的代码。
上级
45bbf0cd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
191 addition
and
173 deletion
+191
-173
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ApplicationExceptionHandler.java
...d/skywalking/buriedpoint/ApplicationExceptionHandler.java
+30
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/LocalBuriedPointSender.java
.../cloud/skywalking/buriedpoint/LocalBuriedPointSender.java
+2
-5
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java
.../cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java
+4
-9
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java
...cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java
+1
-5
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadFactoryBuriedPointSender.java
...kywalking/buriedpoint/ThreadFactoryBuriedPointSender.java
+1
-7
skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java
...pi/src/main/java/com/ai/cloud/skywalking/conf/Config.java
+4
-2
skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java
.../src/main/java/com/ai/cloud/skywalking/protocol/Span.java
+149
-145
未找到文件。
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ApplicationExceptionHandler.java
0 → 100644
浏览文件 @
8ec5d16d
package
com.ai.cloud.skywalking.buriedpoint
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.ai.cloud.skywalking.api.IExceptionHandler
;
import
com.ai.cloud.skywalking.conf.Config
;
import
com.ai.cloud.skywalking.context.Context
;
import
com.ai.cloud.skywalking.protocol.Span
;
public
class
ApplicationExceptionHandler
implements
IExceptionHandler
{
private
static
Boolean
isExclusiveExceptionListInit
=
false
;
private
static
List
<
String
>
exclusiveExceptionList
=
new
ArrayList
<
String
>();
@Override
public
void
handleException
(
Throwable
th
)
{
if
(
isExclusiveExceptionListInit
==
false
)
synchronized
(
isExclusiveExceptionListInit
)
{
if
(
isExclusiveExceptionListInit
==
false
)
{
isExclusiveExceptionListInit
=
true
;
}
}
Span
span
=
Context
.
getLastSpan
();
span
.
handleException
(
th
,
exclusiveExceptionList
,
Config
.
BuriedPoint
.
MAX_EXCEPTION_STACK_LENGTH
);
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/LocalBuriedPointSender.java
浏览文件 @
8ec5d16d
...
...
@@ -14,7 +14,7 @@ import com.ai.cloud.skywalking.util.ContextGenerator;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
LocalBuriedPointSender
implements
IBuriedPointSender
{
public
class
LocalBuriedPointSender
extends
ApplicationExceptionHandler
implements
IBuriedPointSender
{
private
static
Logger
logger
=
Logger
.
getLogger
(
IBuriedPointSender
.
class
.
getName
());
...
...
@@ -53,8 +53,5 @@ public class LocalBuriedPointSender implements IBuriedPointSender {
}
}
public
void
handleException
(
Throwable
e
)
{
Span
span
=
Context
.
getLastSpan
();
span
.
handleException
(
e
,
Config
.
BuriedPoint
.
MAX_EXCEPTION_STACK_LENGTH
);
}
public
void
handleException
(
Throwable
e
)
{}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java
浏览文件 @
8ec5d16d
package
com.ai.cloud.skywalking.buriedpoint
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
com.ai.cloud.skywalking.api.IBuriedPointReceiver
;
import
com.ai.cloud.skywalking.buffer.ContextBuffer
;
import
com.ai.cloud.skywalking.conf.AuthDesc
;
...
...
@@ -10,10 +13,7 @@ import com.ai.cloud.skywalking.model.Identification;
import
com.ai.cloud.skywalking.protocol.Span
;
import
com.ai.cloud.skywalking.util.ContextGenerator
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
RPCBuriedPointReceiver
implements
IBuriedPointReceiver
{
public
class
RPCBuriedPointReceiver
extends
ApplicationExceptionHandler
implements
IBuriedPointReceiver
{
private
static
Logger
logger
=
Logger
.
getLogger
(
LocalBuriedPointSender
.
class
.
getName
());
...
...
@@ -44,9 +44,4 @@ public class RPCBuriedPointReceiver implements IBuriedPointReceiver {
Context
.
append
(
spanData
);
}
public
void
handleException
(
Throwable
e
)
{
Span
span
=
Context
.
getLastSpan
();
span
.
handleException
(
e
,
Config
.
BuriedPoint
.
MAX_EXCEPTION_STACK_LENGTH
);
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java
浏览文件 @
8ec5d16d
...
...
@@ -15,7 +15,7 @@ import com.ai.cloud.skywalking.util.TraceIdGenerator;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
ThreadBuriedPointSender
implements
IBuriedPointSender
{
public
class
ThreadBuriedPointSender
extends
ApplicationExceptionHandler
implements
IBuriedPointSender
{
private
static
Logger
logger
=
Logger
.
getLogger
(
ThreadBuriedPointSender
.
class
.
getName
());
...
...
@@ -71,8 +71,4 @@ public class ThreadBuriedPointSender implements IBuriedPointSender {
}
}
public
void
handleException
(
Throwable
e
)
{
Span
span
=
Context
.
getLastSpan
();
span
.
handleException
(
e
,
Config
.
BuriedPoint
.
MAX_EXCEPTION_STACK_LENGTH
);
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadFactoryBuriedPointSender.java
浏览文件 @
8ec5d16d
...
...
@@ -14,7 +14,7 @@ import com.ai.cloud.skywalking.util.ContextGenerator;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
ThreadFactoryBuriedPointSender
implements
IBuriedPointSender
{
public
class
ThreadFactoryBuriedPointSender
extends
ApplicationExceptionHandler
implements
IBuriedPointSender
{
private
static
Logger
logger
=
Logger
.
getLogger
(
ThreadBuriedPointSender
.
class
.
getName
());
...
...
@@ -49,10 +49,4 @@ public class ThreadFactoryBuriedPointSender implements IBuriedPointSender {
ContextBuffer
.
save
(
spanData
);
}
}
public
void
handleException
(
Throwable
e
)
{
Span
span
=
Context
.
getLastSpan
();
span
.
handleException
(
e
,
Config
.
BuriedPoint
.
MAX_EXCEPTION_STACK_LENGTH
);
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java
浏览文件 @
8ec5d16d
...
...
@@ -3,9 +3,9 @@ package com.ai.cloud.skywalking.conf;
public
class
Config
{
public
static
class
SkyWalking
{
public
static
String
USER_ID
;
public
static
String
USER_ID
=
""
;
public
static
String
APPLICATION_CODE
;
public
static
String
APPLICATION_CODE
=
""
;
}
public
static
class
BuriedPoint
{
...
...
@@ -16,6 +16,8 @@ public class Config {
// Business Key 最大长度
public
static
int
BUSINESSKEY_MAX_LENGTH
=
300
;
public
static
String
EXCLUSIVE_EXCEPTIONS
=
""
;
}
public
static
class
Consumer
{
...
...
skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java
浏览文件 @
8ec5d16d
package
com.ai.cloud.skywalking.protocol
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
Span
extends
SpanData
{
private
Logger
logger
=
Logger
.
getLogger
(
Span
.
class
.
getName
());
public
Span
()
{
}
public
Span
(
String
traceId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
userId
=
userId
;
}
public
Span
(
String
traceId
,
String
parentLevelId
,
int
levelId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
parentLevel
=
parentLevelId
;
this
.
userId
=
userId
;
this
.
levelId
=
levelId
;
}
public
Span
(
String
originData
)
{
String
[]
fieldValues
=
originData
.
split
(
SPAN_FIELD_SPILT_PATTERN
);
traceId
=
fieldValues
[
0
].
trim
();
parentLevel
=
fieldValues
[
1
].
trim
();
levelId
=
Integer
.
valueOf
(
fieldValues
[
2
]);
viewPointId
=
fieldValues
[
3
].
trim
();
startDate
=
Long
.
valueOf
(
fieldValues
[
4
]);
cost
=
Long
.
parseLong
(
fieldValues
[
5
]);
address
=
fieldValues
[
6
].
trim
();
statusCode
=
Byte
.
valueOf
(
fieldValues
[
7
].
trim
());
//异常情况才会存在exceptionStack
if
(
statusCode
==
1
)
{
exceptionStack
=
fieldValues
[
8
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
}
spanType
=
fieldValues
[
9
];
isReceiver
=
Boolean
.
valueOf
(
fieldValues
[
10
]);
businessKey
=
fieldValues
[
11
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
processNo
=
fieldValues
[
12
].
trim
();
applicationId
=
fieldValues
[
13
].
trim
();
userId
=
fieldValues
[
14
].
trim
();
this
.
originData
=
originData
;
}
@Override
public
String
toString
()
{
StringBuilder
toStringValue
=
new
StringBuilder
();
toStringValue
.
append
(
traceId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
parentLevel
))
{
toStringValue
.
append
(
parentLevel
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
levelId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
viewPointId
))
{
toStringValue
.
append
(
viewPointId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
startDate
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
cost
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
address
))
{
toStringValue
.
append
(
address
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
statusCode
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
exceptionStack
))
{
//换行符在各个系统中表现不一致,
//windows平台的换行符为/r/n
//linux平台的换行符为/n
toStringValue
.
append
(
exceptionStack
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
)
.
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
spanType
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
isReceiver
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
businessKey
))
{
//换行符在各个系统中表现不一致,
//windows平台的换行符为/r/n
//linux平台的换行符为/n
toStringValue
.
append
(
businessKey
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
)
.
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
processNo
))
{
toStringValue
.
append
(
processNo
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
applicationId
))
{
toStringValue
.
append
(
applicationId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
userId
))
{
toStringValue
.
append
(
userId
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
return
toStringValue
.
toString
();
}
protected
boolean
isNonBlank
(
String
str
)
{
return
str
!=
null
&&
str
.
length
()
>
0
;
}
public
void
handleException
(
Throwable
e
,
int
maxExceptionStackLength
)
{
this
.
statusCode
=
1
;
ByteArrayOutputStream
buf
=
new
ByteArrayOutputStream
();
StringBuilder
expMessage
=
new
StringBuilder
();
Throwable
causeException
=
e
;
while
(
causeException
!=
null
&&
(
causeException
.
getCause
()
!=
null
||
expMessage
.
length
()
<
maxExceptionStackLength
))
{
causeException
.
printStackTrace
(
new
java
.
io
.
PrintWriter
(
buf
,
true
));
expMessage
.
append
(
buf
.
toString
());
causeException
=
causeException
.
getCause
();
}
try
{
buf
.
close
();
}
catch
(
IOException
e1
)
{
logger
.
log
(
Level
.
ALL
,
"Close exception stack input stream failed"
);
}
this
.
exceptionStack
=
expMessage
.
toString
();
}
private
Logger
logger
=
Logger
.
getLogger
(
Span
.
class
.
getName
());
public
Span
()
{
}
public
Span
(
String
traceId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
userId
=
userId
;
}
public
Span
(
String
traceId
,
String
parentLevelId
,
int
levelId
,
String
applicationID
,
String
userId
)
{
this
.
traceId
=
traceId
;
this
.
applicationId
=
applicationID
;
this
.
parentLevel
=
parentLevelId
;
this
.
userId
=
userId
;
this
.
levelId
=
levelId
;
}
public
Span
(
String
originData
)
{
String
[]
fieldValues
=
originData
.
split
(
SPAN_FIELD_SPILT_PATTERN
);
traceId
=
fieldValues
[
0
].
trim
();
parentLevel
=
fieldValues
[
1
].
trim
();
levelId
=
Integer
.
valueOf
(
fieldValues
[
2
]);
viewPointId
=
fieldValues
[
3
].
trim
();
startDate
=
Long
.
valueOf
(
fieldValues
[
4
]);
cost
=
Long
.
parseLong
(
fieldValues
[
5
]);
address
=
fieldValues
[
6
].
trim
();
statusCode
=
Byte
.
valueOf
(
fieldValues
[
7
].
trim
());
// 异常情况才会存在exceptionStack
if
(
statusCode
==
1
)
{
exceptionStack
=
fieldValues
[
8
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
}
spanType
=
fieldValues
[
9
];
isReceiver
=
Boolean
.
valueOf
(
fieldValues
[
10
]);
businessKey
=
fieldValues
[
11
].
trim
().
replaceAll
(
SPAN_ATTR_SPILT_CHARACTER
,
NEW_LINE_CHARACTER_PATTERN
);
processNo
=
fieldValues
[
12
].
trim
();
applicationId
=
fieldValues
[
13
].
trim
();
userId
=
fieldValues
[
14
].
trim
();
this
.
originData
=
originData
;
}
@Override
public
String
toString
()
{
StringBuilder
toStringValue
=
new
StringBuilder
();
toStringValue
.
append
(
traceId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
parentLevel
))
{
toStringValue
.
append
(
parentLevel
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
levelId
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
viewPointId
))
{
toStringValue
.
append
(
viewPointId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
startDate
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
cost
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
address
))
{
toStringValue
.
append
(
address
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
statusCode
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
exceptionStack
))
{
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue
.
append
(
exceptionStack
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
).
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
toStringValue
.
append
(
spanType
+
SPAN_FIELD_SPILT_PATTERN
);
toStringValue
.
append
(
isReceiver
+
SPAN_FIELD_SPILT_PATTERN
);
if
(
isNonBlank
(
businessKey
))
{
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue
.
append
(
businessKey
.
replaceAll
(
CARRIAGE_RETURN_CHARACTER_PATTERN
,
""
).
replaceAll
(
NEW_LINE_CHARACTER_PATTERN
,
SPAN_ATTR_SPILT_CHARACTER
)
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
processNo
))
{
toStringValue
.
append
(
processNo
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
applicationId
))
{
toStringValue
.
append
(
applicationId
+
SPAN_FIELD_SPILT_PATTERN
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
if
(
isNonBlank
(
userId
))
{
toStringValue
.
append
(
userId
);
}
else
{
toStringValue
.
append
(
" "
+
SPAN_FIELD_SPILT_PATTERN
);
}
return
toStringValue
.
toString
();
}
protected
boolean
isNonBlank
(
String
str
)
{
return
str
!=
null
&&
str
.
length
()
>
0
;
}
public
void
handleException
(
Throwable
e
,
List
<
String
>
exclusiveExceptionList
,
int
maxExceptionStackLength
)
{
this
.
statusCode
=
1
;
ByteArrayOutputStream
buf
=
new
ByteArrayOutputStream
();
StringBuilder
expMessage
=
new
StringBuilder
();
Throwable
causeException
=
e
;
while
(
causeException
!=
null
&&
(
causeException
.
getCause
()
!=
null
||
expMessage
.
length
()
<
maxExceptionStackLength
))
{
causeException
.
printStackTrace
(
new
java
.
io
.
PrintWriter
(
buf
,
true
));
expMessage
.
append
(
buf
.
toString
());
causeException
=
causeException
.
getCause
();
}
try
{
buf
.
close
();
}
catch
(
IOException
e1
)
{
logger
.
log
(
Level
.
ALL
,
"Close exception stack input stream failed"
);
}
this
.
exceptionStack
=
expMessage
.
toString
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录