actuator httpTrace endpoint
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class);
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.trace.http.HttpTrace;
|
||||
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class CustomTraceRepository implements HttpTraceRepository {
|
||||
|
||||
List<HttpTrace> traces = new ArrayList<>(1);
|
||||
|
||||
@Override
|
||||
public List<HttpTrace> findAll() {
|
||||
return traces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(HttpTrace trace) {
|
||||
if ("GET".equals(trace.getRequest().getMethod())) {
|
||||
traces.clear();
|
||||
traces.add(trace);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("echo")
|
||||
public class EchoController {
|
||||
|
||||
@GetMapping
|
||||
public String echo(@RequestParam("msg") String msg) {
|
||||
return "echoing " + msg;
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.spring.boot.management.trace;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.boot.actuate.trace.http.HttpExchangeTracer;
|
||||
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
|
||||
import org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TraceRequestFilter extends HttpTraceFilter {
|
||||
/**
|
||||
* Create a new {@link HttpTraceFilter} instance.
|
||||
*
|
||||
* @param repository the trace repository
|
||||
* @param tracer used to trace exchanges
|
||||
*/
|
||||
public TraceRequestFilter(HttpTraceRepository repository, HttpExchangeTracer tracer) {
|
||||
super(repository, tracer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
||||
return request.getServletPath().contains("actuator");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
management.endpoints.web.exposure.include=httptrace
|
||||
management.trace.http.include=REQUEST_HEADERS
|
||||
|
||||
Reference in New Issue
Block a user