actuator httpTrace endpoint

This commit is contained in:
Marcos Lopez Gonzalez 2019-07-28 16:12:14 +02:00
parent d91741c020
commit 2b602b0485
6 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-management</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-management</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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");
}
}

View File

@ -0,0 +1,3 @@
management.endpoints.web.exposure.include=httptrace
management.trace.http.include=REQUEST_HEADERS