0
votes

I am looking to log all of my Spring-Boot project's request. My pointcuts work fine for my programming, and I can get the sub paths, but not the base actuator path.

  • com.example.demo...(..) - This works for my programming

  • org.springframework.boot.actuate...(..) - This works for paths like http://localhost:8080/actuator/info or http://localhost:8080/actuator/health. This works

None of my pointcuts work for just "http://localhost:8080/actuator" with no other path. I have tried looking through the org.springframework.boot.actuate paths and through the actuator jar to see if I missed a path, but I cannot find anything. I've looked through org.springframework.boot.actuate.autoconfigure, but that doesn't seem to be right.

I just need to capture it and log the request, but I cannot find http://localhost:8080/actuator

Thanks

3

3 Answers

0
votes

You can log all request with defining Filter class. It works also /actuator request.

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

// Run as first filter
@Order(Ordered.HIGHEST_PRECEDENCE)
@Component
public class LogFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        System.out.println(httpRequest.getMethod() + " - " + httpRequest.getRequestURI());
        chain.doFilter(request, response);
        // do anything after response
    }
}
0
votes

Use Actuator HttpTraceFilter to log detail. You can log detail in a file or directly to database.

Sample Inmemory repository

@Repository
public class CustomTraceRepository extends InMemoryTraceRepository {

    private static final Logger log = LoggerFactory.getLogger(CustomTraceRepository.class);

    public CustomTraceRepository() {
        super.setCapacity(200);
    }

    @Override
    public void add(Map<String, Object> map) {
        super.add(map);

        log.info("traced object: {}", map);
    }
}
0
votes

To save someone else the trouble.

The class that serves http://yourhost:8080/actuator base path is

https://github.com/spring-projects/spring-boot/blob/0a4c26532dff6f3fa1bf6d2e1c2a74549191117a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcEndpointHandlerMapping.java

The programming that handles the page, is around line 76 (in current version). Unfortunately, it is an inner class that is not public and Spring AOP doesn't seem to be able to find it.

So, if you are able to, probably the Filter answer above is good, but doing Spring AOP cannot go against that class directly. Unfortunately, the Filter may not work in my situation, but someone else might be glad for this information.