2021年1月17日星期日

How to trace incoming requests with AWS X-Ray on Spring Boot WebFlux?

I have multiple microservices running on AWS ECS and I want to try out AWS X-Ray. Following this developer guide I added a WebConfig.java file with a tracing filter.

Added lines to build.gradle:

implementation "javax.servlet:javax.servlet-api:4.0.1"  implementation "com.amazonaws:aws-xray-recorder-sdk-core:2.8.0"  

New file WebConfig.java:

import com.amazonaws.xray.javax.servlet.AWSXRayServletFilter;  import javax.servlet.Filter;  import org.springframework.context.annotation.Bean;  import org.springframework.context.annotation.Configuration;    @Configuration  public class WebConfig {      @Bean    public Filter tracingFilter() {      return new AWSXRayServletFilter("ordermicroservice");    }  }  

However, I don't think this is correct, mostly because I had to add the extra dependency for the javax.servlet.Filter. I think this is because I'm using spring-boot-webflux and not spring-boot-web. So I have a Netty webserver and not a Tomcat webserver.

My questions are:

  • How can I add logging to a servlet filter, to make sure that every incoming HTTP request is passing correctly through the filter?
  • What is the correct way to write a web filter in spring-boot-webflux projects, which use Netty and not Tomcat?
https://stackoverflow.com/questions/65733569/how-to-trace-incoming-requests-with-aws-x-ray-on-spring-boot-webflux January 15, 2021 at 05:31PM

没有评论:

发表评论