Trace http requests with Spring Actuator

List the last http request with ease

Spring Actuator provides also a httptrace endpoint. You get the last HTTP request with /httptrace.

After adding Spring Boot Actuator dependencies to your project dependencies, you have to expose the httptrace endpoint via your application.properties:

management.endpoints.web.exposure.include=httptrace

curl http://127.0.0.1:8080/actuator/httptrace | jq
{
    "traces": [{
        "timestamp": "2019-01-05T07:45:14.406Z",
        "principal": null,
        "session": null,
        "request": {
            "method": "GET",
            "uri": "http://127.0.0.1:8080/helloworld/peter",
            "headers": {
                    "host": ["127.0.0.1:8080"],
                    "accept": ["*/*"],
                    "user-agent": ["curl/7.58.0"]
            },
            "remoteAddress": null
        },
        "response": {
            "status": 200,
            "headers": {
                    "Content-Length": ["16"],
                    "Date": ["Sat, 05 Jan 2019 07:45:14 GMT"],
                    "Content-Type": ["text/plain;charset=UTF-8"]
            }
        },
        "timeTaken": 7
    }]
}

In Spring Boot 2.0 the trace endpoint was renamed to httptrace. You can even configure the trace details (see TraceProperties.java code).
Here is an example

management.httptrace.include = parameter


Here is the source code of my sample application 🙂

Links

List of Spring Actuator endpoints
List of Spring application properties