-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问spirngboot中自定义的容器怎么获取TraceId? #17
Comments
你如果用到了 tlog-web-spring-boot-starter 这个引入方式, TLog默认使用的是TLogWebInterceptor拦截器操作TLogContext上下文信息,因为过滤器前置是先于拦截器前置执行的,所以过滤器链调用前置操作的log输出打印不出来,对于过滤器链调用后置操作的log是因为过滤器的后置是晚于拦截器的后置执行的,已经被TLogWebInterceptor后置操作清除了,所以也打印不出来,这个是实现机制导致的,有三种解决办法:
package com.example.demo;
import com.yomahub.tlog.constant.TLogConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author Oct
*/
@Slf4j
@Component
public class NormalFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
log.debug("normal-filter - before");
filterChain.doFilter(servletRequest, servletResponse);
String traceId = null;
if (servletResponse instanceof HttpServletResponse) {
traceId = ((HttpServletResponse) servletResponse).getHeader(TLogConstants.TLOG_TRACE_KEY);
}
log.debug("[{}] normal-filter - after", traceId);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如上,我这里打印了http请求和响应日志,但是并没有traceId
The text was updated successfully, but these errors were encountered: