Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
javalover123888
SkyWalking
提交
5e6634d6
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,发现更多精彩内容 >>
提交
5e6634d6
编写于
1月 09, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add commonts of toolkits, and their activations.
上级
1ab4858f
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
113 addition
and
26 deletion
+113
-26
skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java
...ywalking/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java
+7
-1
skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log/log4j/v2/x/TraceIdConverter.java
...e/skywalking/toolkit/log/log4j/v2/x/TraceIdConverter.java
+5
-0
skywalking-application-toolkit/skywalking-toolkit-logback-1.x/src/main/java/com/a/eye/skywalking/toolkit/log/logback/v1/x/LogbackPatternConverter.java
...ing/toolkit/log/logback/v1/x/LogbackPatternConverter.java
+7
-0
skywalking-application-toolkit/skywalking-toolkit-logback-1.x/src/main/java/com/a/eye/skywalking/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java
...toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java
+4
-0
skywalking-application-toolkit/skywalking-toolkit-trace-context/src/main/java/com/a/eye/skywalking/toolkit/trace/TraceContext.java
...java/com/a/eye/skywalking/toolkit/trace/TraceContext.java
+10
-0
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/Tracing.java
...g-api/src/main/java/com/a/eye/skywalking/api/Tracing.java
+2
-23
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java
...it/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java
+8
-0
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java
...ion/log/log4j/v1/x/TraceIdPatternConverterActivation.java
+15
-0
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java
...vation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java
+11
-0
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java
...it/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java
+7
-1
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java
...n/log/logback/v1/x/LogbackPatternConverterActivation.java
+16
-1
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java
.../activation/log/logback/v1/x/PrintTraceIdInterceptor.java
+8
-0
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextActivation.java
...king/toolkit/activation/trace/TraceContextActivation.java
+11
-0
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextInterceptor.java
...ing/toolkit/activation/trace/TraceContextInterceptor.java
+2
-0
未找到文件。
skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log/log4j/v2/x/Log4j2OutputAppender.java
浏览文件 @
5e6634d6
...
...
@@ -4,7 +4,13 @@ package com.a.eye.skywalking.toolkit.log.log4j.v2.x;
* Created by wusheng on 2016/12/11.
*/
public
class
Log4j2OutputAppender
{
public
static
void
append
(
StringBuilder
toAppendTo
){
/**
* As default, append "TID: N/A" to the output message,
* if sky-walking agent in active mode, append the real traceId in the recent Context, if existed, or empty String.
*
* @param toAppendTo origin output message.
*/
public
static
void
append
(
StringBuilder
toAppendTo
)
{
toAppendTo
.
append
(
"TID: N/A"
);
}
}
skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log/log4j/v2/x/TraceIdConverter.java
浏览文件 @
5e6634d6
...
...
@@ -7,6 +7,11 @@ import org.apache.logging.log4j.core.pattern.ConverterKeys;
import
org.apache.logging.log4j.core.pattern.LogEventPatternConverter
;
/**
* {@link TraceIdConverter} is a log4j2 plugin, by annotation as {@link Plugin}.
* It convert the pattern key: traceId.
* Use '%traceId' in log4j2's config: <PatternLayout pattern="%d [%traceId] %-5p %c{1}:%L - %m%n"/>,
* '%traceId' will output as TID:xxxx
*
* Created by wusheng on 2016/12/7.
*/
@Plugin
(
name
=
"TraceIdConverter"
,
category
=
"Converter"
)
...
...
skywalking-application-toolkit/skywalking-toolkit-logback-1.x/src/main/java/com/a/eye/skywalking/toolkit/log/logback/v1/x/LogbackPatternConverter.java
浏览文件 @
5e6634d6
...
...
@@ -7,6 +7,13 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
* Created by wusheng on 2016/12/7.
*/
public
class
LogbackPatternConverter
extends
ClassicConverter
{
/**
* As default, return "TID: N/A" to the output message,
* if sky-walking agent in active mode, return the real traceId in the recent Context, if existed.
*
* @param iLoggingEvent
* @return the traceId: N/A, empty String, or the real traceId.
*/
@Override
public
String
convert
(
ILoggingEvent
iLoggingEvent
)
{
return
"TID: N/A"
;
...
...
skywalking-application-toolkit/skywalking-toolkit-logback-1.x/src/main/java/com/a/eye/skywalking/toolkit/log/logback/v1/x/TraceIdPatternLogbackLayout.java
浏览文件 @
5e6634d6
...
...
@@ -3,6 +3,10 @@ package com.a.eye.skywalking.toolkit.log.logback.v1.x;
import
ch.qos.logback.classic.PatternLayout
;
/**
* Based on the logback-compoenent convert register mechanism,
* register {@link LogbackPatternConverter} as a new convert, match to "tid".
* You can use "%tid" in logback config file, "Pattern" section.
* <p>
* Created by wusheng on 2016/12/7.
*/
public
class
TraceIdPatternLogbackLayout
extends
PatternLayout
{
...
...
skywalking-application-toolkit/skywalking-toolkit-trace-context/src/main/java/com/a/eye/skywalking/toolkit/trace/TraceContext.java
浏览文件 @
5e6634d6
package
com.a.eye.skywalking.toolkit.trace
;
/**
* Try to access the sky-walking tracer context.
* The context is not existed, always.
* only the middleware, component, or rpc-framework are supported in the current invoke stack, in the same thread,
* the context will be available.
* <p>
* Created by xin on 2016/12/15.
*/
public
class
TraceContext
{
/**
* Try to get the traceId of current trace context.
*
* @return traceId, if it exists, or empty {@link String}.
*/
public
static
String
traceId
()
{
return
""
;
}
...
...
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/Tracing.java
浏览文件 @
5e6634d6
...
...
@@ -9,9 +9,9 @@ import static com.a.eye.skywalking.util.TraceIdUtil.formatTraceId;
public
class
Tracing
{
/**
*
获取当前上下文中的TraceId
*
Get the traceId of current trace context.
*
* @return
* @return
traceId, if it exists, or empty {@link String}.
*/
public
static
String
getTraceId
()
{
Span
spanData
=
CurrentThreadSpanStack
.
peek
();
...
...
@@ -21,25 +21,4 @@ public class Tracing {
return
formatTraceId
(
spanData
.
getTraceId
());
}
public
static
String
getTracelevelId
()
{
Span
spanData
=
CurrentThreadSpanStack
.
peek
();
if
(
spanData
==
null
)
{
return
""
;
}
return
(
spanData
.
getParentLevel
()
==
null
||
spanData
.
getParentLevel
().
length
()
==
0
)
?
Integer
.
toString
(
spanData
.
getLevelId
())
:
spanData
.
getParentLevel
()
+
"."
+
spanData
.
getLevelId
();
}
public
static
String
generateNextContextData
()
{
Span
spanData
=
CurrentThreadSpanStack
.
peek
();
if
(
spanData
==
null
)
{
return
null
;
}
ContextData
contextData
=
new
ContextData
(
spanData
);
return
contextData
.
toString
();
}
}
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/PrintTraceIdInterceptor.java
浏览文件 @
5e6634d6
...
...
@@ -15,6 +15,14 @@ public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor
}
/**
* Override com.a.eye.skywalking.toolkit.log.log4j.v1.x.TraceIdPatternConverter.convert(),
*
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
* @param interceptorContext method context, includes class name, method name, etc.
* @param ret the method's original return value.
* @return the traceId
*/
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
return
"TID:"
+
Tracing
.
getTraceId
();
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java
浏览文件 @
5e6634d6
...
...
@@ -2,6 +2,7 @@ package com.a.eye.skywalking.toolkit.activation.log.log4j.v1.x;
import
com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
...
...
@@ -9,19 +10,33 @@ import net.bytebuddy.matcher.ElementMatcher;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* Active the toolkit class "com.a.eye.skywalking.toolkit.log.log4j.v1.x.TraceIdPatternConverter".
* Should not dependency or import any class in "skywalking-toolkit-log4j-1.x" module.
* Activation's classloader is diff from "com.a.eye.skywalking.toolkit.log.log4j.v1.x.TraceIdPatternConverter",
* using direct will trigger classloader issue.
*
* Created by wusheng on 2016/12/7.
*/
public
class
TraceIdPatternConverterActivation
extends
ClassInstanceMethodsEnhancePluginDefine
{
/**
* @return the target class, which needs active.
*/
@Override
protected
String
enhanceClassName
()
{
return
"com.a.eye.skywalking.toolkit.log.log4j.v1.x.TraceIdPatternConverter"
;
}
/**
* @return null, no need to intercept constructor of enhance class.
*/
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
null
;
}
/**
* @return the collection of {@link InstanceMethodsInterceptPoint}, represent the intercepted methods and their interceptors.
*/
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java
浏览文件 @
5e6634d6
...
...
@@ -8,14 +8,25 @@ import net.bytebuddy.matcher.ElementMatcher;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* Active the toolkit class "com.a.eye.skywalking.toolkit.log.logback.v2.x.LogbackPatternConverter".
* Should not dependency or import any class in "skywalking-toolkit-logback-2.x" module.
* Activation's classloader is diff from "com.a.eye.skywalking.toolkit.log.logback.v2.x.LogbackPatternConverter",
* using direct will trigger classloader issue.
*
* Created by wusheng on 2016/12/7.
*/
public
class
Log4j2OutputAppenderActivation
extends
ClassStaticMethodsEnhancePluginDefine
{
/**
* @return the target class, which needs active.
*/
@Override
protected
String
enhanceClassName
()
{
return
"com.a.eye.skywalking.toolkit.log.log4j.v2.x.Log4j2OutputAppender"
;
}
/**
* @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their interceptors.
*/
@Override
protected
StaticMethodsInterceptPoint
[]
getStaticMethodsInterceptPoints
()
{
return
new
StaticMethodsInterceptPoint
[]{
new
StaticMethodsInterceptPoint
()
{
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/log4j/v2/x/PrintTraceIdInterceptor.java
浏览文件 @
5e6634d6
...
...
@@ -8,9 +8,15 @@ import com.a.eye.skywalking.plugin.interceptor.enhance.*;
* Created by wusheng on 2016/12/7.
*/
public
class
PrintTraceIdInterceptor
implements
StaticMethodsAroundInterceptor
{
/**
* Override com.a.eye.skywalking.toolkit.log.log4j.v2.x.Log4j2OutputAppender.append(),
*
* @param interceptorContext method context, includes class name, method name, etc.
* @param result change this result, to output the traceId. The origin append() method will not invoke.
*/
@Override
public
void
beforeMethod
(
StaticMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
((
StringBuilder
)
interceptorContext
.
allArguments
()[
0
]).
append
(
"TID:"
+
Tracing
.
getTraceId
());
((
StringBuilder
)
interceptorContext
.
allArguments
()[
0
]).
append
(
"TID:"
+
Tracing
.
getTraceId
());
//make sure origin method do not invoke.
result
.
defineReturnValue
(
null
);
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java
浏览文件 @
5e6634d6
...
...
@@ -2,6 +2,7 @@ package com.a.eye.skywalking.toolkit.activation.log.logback.v1.x;
import
com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
...
...
@@ -9,22 +10,36 @@ import net.bytebuddy.matcher.ElementMatcher;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* Active the toolkit class "com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter".
* Should not dependency or import any class in "skywalking-toolkit-logback-1.x" module.
* Activation's classloader is diff from "com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter",
* using direct will trigger classloader issue.
* <p>
* Created by wusheng on 2016/12/7.
*/
public
class
LogbackPatternConverterActivation
extends
ClassInstanceMethodsEnhancePluginDefine
{
/**
* @return the target class, which needs active.
*/
@Override
protected
String
enhanceClassName
()
{
return
"com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter"
;
}
/**
* @return null, no need to intercept constructor of enhance class.
*/
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
null
;
}
/**
* @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their interceptors.
*/
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"convert"
);
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/PrintTraceIdInterceptor.java
浏览文件 @
5e6634d6
...
...
@@ -15,6 +15,14 @@ public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor
}
/**
* Override com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter.convert(),
*
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
* @param interceptorContext method context, includes class name, method name, etc.
* @param ret the method's original return value.
* @return the traceId
*/
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
return
"TID:"
+
Tracing
.
getTraceId
();
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextActivation.java
浏览文件 @
5e6634d6
...
...
@@ -8,14 +8,25 @@ import net.bytebuddy.matcher.ElementMatcher;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* Active the toolkit class "com.a.eye.skywalking.toolkit.trace.TraceContext".
* Should not dependency or import any class in "skywalking-toolkit-trace-context" module.
* Activation's classloader is diff from "com.a.eye.skywalking.toolkit.trace.TraceContext",
* using direct will trigger classloader issue.
* <p>
* Created by xin on 2016/12/15.
*/
public
class
TraceContextActivation
extends
ClassStaticMethodsEnhancePluginDefine
{
/**
* @return the target class, which needs active.
*/
@Override
protected
String
enhanceClassName
()
{
return
"com.a.eye.skywalking.toolkit.trace.TraceContext"
;
}
/**
* @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their interceptors.
*/
@Override
protected
StaticMethodsInterceptPoint
[]
getStaticMethodsInterceptPoints
()
{
return
new
StaticMethodsInterceptPoint
[]
{
new
StaticMethodsInterceptPoint
()
{
...
...
skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextInterceptor.java
浏览文件 @
5e6634d6
...
...
@@ -9,6 +9,8 @@ import com.a.eye.skywalking.plugin.interceptor.enhance.StaticMethodInvokeContext
import
com.a.eye.skywalking.plugin.interceptor.enhance.StaticMethodsAroundInterceptor
;
/**
*
*
* Created by xin on 2016/12/15.
*/
public
class
TraceContextInterceptor
implements
StaticMethodsAroundInterceptor
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录