mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、新增tracefilter中的trace-id,服务日志mdc打印和请求响应增加trace-id;2、恢复access_api_log和access_error_log的清理定时任务;3、补充服务中的线程池使用TransmittableThreadLocal;
This commit is contained in:
+15
-11
@@ -1,6 +1,6 @@
|
||||
package com.cf.imes.framework.tracer.core.filter;
|
||||
|
||||
import com.cf.imes.framework.common.util.monitor.TracerUtils;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
@@ -8,6 +8,9 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.cf.imes.framework.common.enums.TraceConstants.TRACE_ID;
|
||||
|
||||
/**
|
||||
* Trace 过滤器,打印 traceId 到 header 中返回
|
||||
@@ -15,19 +18,20 @@ import java.io.IOException;
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
public class TraceFilter extends OncePerRequestFilter {
|
||||
|
||||
/**
|
||||
* Header 名 - 链路追踪编号
|
||||
*/
|
||||
private static final String HEADER_NAME_TRACE_ID = "trace-id";
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
// 设置响应 traceId
|
||||
response.addHeader(HEADER_NAME_TRACE_ID, TracerUtils.getTraceId());
|
||||
// 继续过滤
|
||||
chain.doFilter(request, response);
|
||||
String traceId = UUID.randomUUID().toString();
|
||||
try {
|
||||
// 设置日志跟踪ID
|
||||
MDC.put(TRACE_ID, traceId);
|
||||
// 继续过滤
|
||||
chain.doFilter(request, response);
|
||||
} finally {
|
||||
System.out.println("traceId: " + traceId);
|
||||
// 清理跟踪ID
|
||||
MDC.remove(TRACE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user