在将请求转发到RestController之前,我正在使用自定义过滤器来验证http请求。
Sleuth仅从控制器层附加跟踪ID和跨度ID,而不为过滤器中的日志附加跟踪ID。
我从下面的Spring Sleuth文档中看到了
“从Spring应用程序(Servlet过滤器,异步端点,REST模板,计划的操作,消息通道,Zuul过滤器和Feign客户端)中引入公共入口和出口点。”
它说该范围支持“ servlet过滤器”,但不适用于我。
下面是代码,请告诉我是否需要进行任何配置才能将跟踪应用于过滤器
spring.zipkin.base-url=loclhost:9411
spring.zipkin.sender.type=web
spring.sleuth.propagation-keys=x-request-id
spring.sleuth.log.slf4j.whitelisted-mdc-keys=x-request-id
spring.sleuth.async.enabled=false
spring.sleuth.web.additionalSkipPattern=/admin/*
FilterConfig.class
@Configuration
public class FilterConfig {
private CustomFilter customFilter;
FilterConfig(CustomFilter customFilter) {
this.customFilter = customFilter;
}
@Bean
public FilterRegistrationBean<CustomFilter> filterRegistrationBean() {
FilterRegistrationBean<CustomFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(customFilter);
registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return registrationBean;
}
}
CustomFilter.class
@Slf4j
@Component
public class CustomFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
.....
}
}