How to trace http requests with the help of spring boot actuator

Posted by Java developer blog on October 17, 2020

Overview

In the post, we are going to trace http requests with the help of a spring boot actuator.

Tracing http requests with the help of spring boot actuator

Firstly, add spring-boot-starter-actuator dependency to the pom.xml file:

1
2
3
4
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Secondly, enable HTTP tracing by adding the following Configuration bean to the project:

1
2
3
4
5
6
7
8
9
@Configuration
public class HttpTraceActuatorConfiguration {

    @Bean
    public HttpTraceRepository httpTraceRepository() {
        return new InMemoryHttpTraceRepository();
    }

}

We have to do it because Actuator HTTP Trace and Auditing features are not enabled by default anymore in Spring-Boot-2.2.0.

Thirdly, Add the following lines to the application.properties:

1
2
management.endpoints.web.exposure.include=httptrace
management.endpoints.enabled-by-default=true

or in yml format:

1
2
3
4
5
6
management:
  endpoints:
    web:
      exposure:
        include: "httptrace"
    enabled-by-default: true

You could find all available endpoints here.

Lastly, you could check out out the last 100 http requests by the following link: http://localhost:8080/actuator/httptrace

Replace hostname and port if needed.

Conclusion

We have described how to trace http requests with the help of a spring boot actuator.