feat(log): 添加traceId
This commit is contained in:
+9
@@ -25,10 +25,12 @@
|
||||
*/
|
||||
package org.springblade.core.cloud.feign;
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.constant.BladeConstant;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.core.tool.utils.ThreadLocalUtil;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
@@ -57,6 +59,13 @@ public class BladeFeignRequestInterceptor implements RequestInterceptor {
|
||||
values.forEach(value -> requestTemplate.header(key, value))
|
||||
);
|
||||
}
|
||||
if (!requestTemplate.headers().containsKey(BladeConstant.TRACE_ID_HEADER)) {
|
||||
// 不包含traceId请求头,且traceId不为空,则添加
|
||||
String traceId = MDC.get(BladeConstant.MDC_TRACE_ID_KEY);
|
||||
if (StringUtil.isNotBlank(traceId)) {
|
||||
requestTemplate.header(BladeConstant.TRACE_ID_HEADER, traceId);
|
||||
}
|
||||
}
|
||||
// 如果是 API Key 认证则跳过设置
|
||||
if (AuthUtil.isApiKeyRequest()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user