Skip to content

Commit 8c3ee71

Browse files
committed
update from gridea: 2023-02-21 19:35:08
0 parents  commit 8c3ee71

18 files changed

Lines changed: 2384 additions & 0 deletions

File tree

404.html

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Page Not Found</title>
8+
<style>
9+
* {
10+
margin: 0;
11+
padding: 0;
12+
}
13+
body {
14+
display: flex;
15+
flex-direction: column;
16+
height: 100vh;
17+
text-align: center;
18+
}
19+
.box {
20+
flex: 1;
21+
display: flex;
22+
justify-content: center;
23+
flex-direction: column;
24+
}
25+
.number {
26+
font-size: 80px;
27+
color: #666;
28+
font-weight: bold;
29+
}
30+
.text {
31+
font-size: 14px;
32+
margin: 24px;
33+
color: #333;
34+
}
35+
.btn-container {
36+
display: flex;
37+
justify-content: center;
38+
}
39+
.btn {
40+
padding: 8px 24px;
41+
display: inline-block;
42+
text-decoration: none;
43+
background: #fff;
44+
border: 2px solid #efefef;
45+
color: #333;
46+
margin: 24px;
47+
border-radius: 20px;
48+
cursor: pointer;
49+
display: flex;
50+
align-items: center;
51+
}
52+
.footer {
53+
padding: 16px;
54+
border-top: 1px solid #efefef;
55+
color: #777;
56+
font-weight: lighter;
57+
}
58+
.footer a {
59+
text-decoration: none;
60+
font-weight: bold;
61+
color: #000;
62+
}
63+
</style>
64+
</head>
65+
<body>
66+
<div class="box">
67+
<div class="number">4 0 4</div>
68+
<div class="text">
69+
Page not found
70+
</div>
71+
<div class="btn-container">
72+
<a class="btn" id="back">
73+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" style="margin-right: 8px;">
74+
<path fill="none" d="M0 0h24v24H0z"/>
75+
<path d="M5.828 7l2.536 2.536L6.95 10.95 2 6l4.95-4.95 1.414 1.414L5.828 5H13a8 8 0 1 1 0 16H4v-2h9a6 6 0 1 0 0-12H5.828z"/>
76+
</svg>
77+
Back
78+
</a>
79+
</div>
80+
</div>
81+
<footer class="footer">
82+
Powered by <a href="https://gridea.dev" target="_blank">Gridea</a>
83+
</footer>
84+
<script>
85+
var back = document.getElementById('back')
86+
back.onclick = function() { console.log('run...'); history.back() }
87+
</script>
88+
</body>
89+
</html>

CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.io

archives/index.html

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" >
5+
6+
<title>文章归档 | Coder</title>
7+
8+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
9+
10+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
11+
<link rel="shortcut icon" href="https://sruby.github.io/favicon.ico?v=1676979268098">
12+
<link rel="stylesheet" href="https://sruby.github.io/styles/main.css">
13+
14+
15+
16+
<link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />
17+
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
18+
19+
20+
21+
<meta name="description" content="Try again,fail again,fail better">
22+
</head>
23+
<body>
24+
<div id="app" class="main">
25+
26+
<div class="sidebar" :class="{ 'full-height': menuVisible }">
27+
<div class="top-container" data-aos="fade-right">
28+
<div class="top-header-container">
29+
<a class="site-title-container" href="https://sruby.github.io">
30+
<img src="https://sruby.github.io/images/avatar.png?v=1676979268098" class="site-logo">
31+
<h1 class="site-title">Coder</h1>
32+
</a>
33+
<div class="menu-btn" @click="menuVisible = !menuVisible">
34+
<div class="line"></div>
35+
</div>
36+
</div>
37+
<div>
38+
39+
40+
<a href="/" class="site-nav">
41+
首页
42+
</a>
43+
44+
45+
46+
<a href="/archives" class="site-nav">
47+
归档
48+
</a>
49+
50+
51+
52+
<a href="/tags" class="site-nav">
53+
标签
54+
</a>
55+
56+
57+
58+
<a href="/post/about" class="site-nav">
59+
关于
60+
</a>
61+
62+
63+
</div>
64+
</div>
65+
<div class="bottom-container" data-aos="flip-up" data-aos-offset="0">
66+
<div class="social-container">
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
</div>
79+
<div class="site-description">
80+
Try again,fail again,fail better
81+
</div>
82+
<div class="site-footer">
83+
Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a> | <a class="rss" href="https://sruby.github.io/atom.xml" target="_blank">RSS</a>
84+
</div>
85+
</div>
86+
</div>
87+
88+
89+
<div class="main-container">
90+
<div class="content-container" data-aos="fade-up">
91+
92+
93+
<h2 class="archives-title">文章归档</h2>
94+
<div class="archives-container">
95+
96+
<h2 class="year" data-aos="fade-in" data-aos-delay="500">2023</h2>
97+
98+
99+
<article class="post">
100+
<a href="https://sruby.github.io/post/spring-cloud-gateway-ri-zhi-wu-fa-ji-lu-skywalking-de-tid/">
101+
<h2 class="post-title">
102+
Spring Cloud Gateway日志无法记录SkyWalking的TID
103+
</h2>
104+
</a>
105+
</article>
106+
107+
108+
109+
</div>
110+
111+
<div class="pagination-container">
112+
113+
114+
</div>
115+
116+
</div>
117+
</div>
118+
</div>
119+
120+
<script src="https://unpkg.com/aos@next/dist/aos.js"></script>
121+
<script type="application/javascript">
122+
123+
AOS.init();
124+
125+
var app = new Vue({
126+
el: '#app',
127+
data: {
128+
menuVisible: false,
129+
},
130+
})
131+
132+
</script>
133+
134+
135+
136+
137+
138+
139+
</body>
140+
</html>

atom.xml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<feed xmlns="http://www.w3.org/2005/Atom">
3+
<id>https://sruby.github.io</id>
4+
<title>Coder</title>
5+
<updated>2023-02-21T11:35:07.166Z</updated>
6+
<generator>https://github.com/jpmonette/feed</generator>
7+
<link rel="alternate" href="https://sruby.github.io"/>
8+
<link rel="self" href="https://sruby.github.io/atom.xml"/>
9+
<subtitle>Try again,fail again,fail better</subtitle>
10+
<logo>https://sruby.github.io/images/avatar.png</logo>
11+
<icon>https://sruby.github.io/favicon.ico</icon>
12+
<rights>All rights reserved 2023, Coder</rights>
13+
<entry>
14+
<title type="html"><![CDATA[Spring Cloud Gateway日志无法记录SkyWalking的TID]]></title>
15+
<id>https://sruby.github.io/post/spring-cloud-gateway-ri-zhi-wu-fa-ji-lu-skywalking-de-tid/</id>
16+
<link href="https://sruby.github.io/post/spring-cloud-gateway-ri-zhi-wu-fa-ji-lu-skywalking-de-tid/">
17+
</link>
18+
<updated>2023-02-20T05:58:10.000Z</updated>
19+
<content type="html"><![CDATA[<h1 id="问题">问题</h1>
20+
<p>在继承了SkyWalking日志工具的情况下,Spring Cloud Gateway的日志中TID为N/A,其他服务的日志均能够正常记录TID。<br>
21+
SkyWalking UI可以正常记录包括Spring Cloud Gateway在内的各个服务的TID。</p>
22+
<h1 id="原因">原因</h1>
23+
<p>SkyWalking agent plugin只保证将TID传递给OAP,而不保证一定把TID输出到日志。<br>
24+
如果需要支持,则需要使用方增加此特性。</p>
25+
<h1 id="agent-plugin源码分析">Agent plugin源码分析</h1>
26+
<p>Spring Cloud Gateway对应的plugin源码如下:<br>
27+
Agent plugin:spring-webflux-5.x-plugin<br>
28+
类:DispatcherHandlerHandleMethodInterceptor</p>
29+
<pre><code class="language-java">@Override
30+
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class&lt;?&gt;[] argumentsTypes,
31+
MethodInterceptResult result) throws Throwable {
32+
EnhancedInstance instance = getInstance(allArguments[0]);
33+
34+
ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
35+
36+
ContextCarrier carrier = new ContextCarrier();
37+
CarrierItem next = carrier.items();
38+
HttpHeaders headers = exchange.getRequest().getHeaders();
39+
while (next.hasNext()) {
40+
next = next.next();
41+
List&lt;String&gt; header = headers.get(next.getHeadKey());
42+
if (header != null &amp;&amp; header.size() &gt; 0) {
43+
next.setHeadValue(header.get(0));
44+
}
45+
}
46+
47+
AbstractSpan span = ContextManager.createEntrySpan(exchange.getRequest().getURI().getPath(), carrier);
48+
49+
if (instance != null &amp;&amp; instance.getSkyWalkingDynamicField() != null) {
50+
ContextManager.continued((ContextSnapshot) instance.getSkyWalkingDynamicField());
51+
}
52+
span.setComponent(ComponentsDefine.SPRING_WEBFLUX);
53+
SpanLayer.asHttp(span);
54+
Tags.URL.set(span, exchange.getRequest().getURI().toString());
55+
HTTP.METHOD.set(span, exchange.getRequest().getMethodValue());
56+
instance.setSkyWalkingDynamicField(ContextManager.capture());
57+
span.prepareForAsync();
58+
ContextManager.stopSpan(span);
59+
//SKYWALING_SPAN保存到exchange
60+
exchange.getAttributes().put(&quot;SKYWALING_SPAN&quot;, span);
61+
}
62+
</code></pre>
63+
<h1 id="solution">Solution</h1>
64+
<h1 id="solution-1">Solution 1</h1>
65+
<ul>
66+
<li>只需要在filter中记录TID,便于排查问题,而不保存到日志框架的MDC种。</li>
67+
<li>根据源码分析部分可以得知plugin会把SKYWALING_SPAN保存到exchange<br>
68+
中,所以我们可以在exchange中获取SKYWALING_SPAN。</li>
69+
<li>从exchange中获取到Span对象后,需要通过反射的方式一层层获取到traceid,因为无法直接依赖包含这些类的agent-core包,会跟agent本身发生冲突。</li>
70+
</ul>
71+
<pre><code class="language-java">String traceId = &quot;N/A&quot;;
72+
Object skywalingSpanObject = exchange.getAttributes().get(&quot;SKYWALING_SPAN&quot;);
73+
if (ObjectUtils.isNotEmpty(skywalingSpanObject)) {
74+
try {
75+
Field owner = FieldUtils.getField(skywalingSpanObject.getClass(), &quot;owner&quot;, true);
76+
Object tracingContext = owner.get(skywalingSpanObject);
77+
Field segmentField = FieldUtils.getField(tracingContext.getClass(), &quot;segment&quot;, true);
78+
Object segment = segmentField.get(tracingContext);
79+
Field relatedGlobalTraceIdField = FieldUtils.getField(segment.getClass(), &quot;relatedGlobalTraceId&quot;, true);
80+
Object relatedGlobalTraceId = relatedGlobalTraceIdField.get(segment);
81+
String traceIdObject = relatedGlobalTraceId.toString();
82+
traceId = Stringutils.substrΩingBetween(traceIdObject, &quot;=&quot;, &quot;)&quot;);
83+
} catch (Exception e) {
84+
log.warn(&quot;get TID failed&quot;, e);
85+
}
86+
</code></pre>
87+
<h1 id="reference">Reference</h1>
88+
<blockquote>
89+
<p><a href="https://github.com/apache/skywalking/discussions/9232">SpringCloudGateway3.1.3, With apm-log4j2-2.x:8.10.0, does not display the real traceId, always display 'TID: N/A' · Discussion #9232 · apache/skywalking (github.com)</a><br>
90+
<a href="https://github.com/apache/skywalking/issues/5268">My log can't get traceId when I use Spring Cloud Gateway in my project ,all traceId in my log is &quot;[traceId:TID:N/A]&quot; · Issue #5268 · apache/skywalking (github.com)</a><br>
91+
<a href="https://www.jianshu.com/p/40727a0b9604">SpringCloudGateway使用Skywalking时日志打印traceId - 简书 (jianshu.com)</a></p>
92+
</blockquote>
93+
<p>#SkyWalking<br>
94+
#SpringCloudGateway<br>
95+
#MDC<br>
96+
#TracdID</p>
97+
]]></content>
98+
</entry>
99+
</feed>

favicon.ico

379 KB
Binary file not shown.

images/avatar.png

292 KB
Loading

0 commit comments

Comments
 (0)