-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
When accessing the Actuator /trace
endpoint, when the management.trace.include
property includes 'parameters', I expect request parameters to be shown in the JSON response. Instead, the parameters JSON element is always empty.
This appears to be due to a setting in the Embedded Tomcat server. In tomcat-embed-core-8.5.11.jar
, the org.apache.catalina.connector.Request
class, recycle()
method contains:
if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
parameterMap = new ParameterMap<>();
} else {
parameterMap.setLocked(false);
parameterMap.clear();
}
If the else clause is executed (as it is by default), it uses a single ParameterMap
instance for all calls to getParameterMap()
. When a request is cleared down, the parameters are cleared using parameterMap.clear()
. This instance of ParameterMap
is added to the Trace object by the WebRequestTraceFilter
. When the Request calls the clear()
method is called on the ParameterMap
, it clears out the instance held by the Trace object, resulting in an empty parameter list when /trace is invoked.
A workaround is to call
System.setProperty("org.apache.catalina.connector.RECYCLE_FACADES", "true");
in the @SpringBootApplication
class, before SpringApplication.run
is called.This makes the Request.recycle()
method create a new instance of ParameterMap
.
A suggested solution would be to deep copy the ParameterMap
in WebRequestTraceFilter
before creating the Trace object.
Found in Spring Boot version 1.5.2.RELEASE
Demonstrated in https://github.com/hotblac/actuator-demo
Steps to reproduce:
- Build and run the actuator-demo project (mvn clean install, java -Dserver.port=18080 -jar target/actuator-demo-0.0.1-SNAPSHOT.jar)
- Hit the simple endpoint: http://localhost:18080/simple?param1=value1¶m2=value2
- Request the actuator trace: http://localhost:18080/trace
Expected:
Response is
[
{
"timestamp": "2017-04-11 19:40:50",
"info": {
"method": "GET",
"path": "/simple",
"headers": {},
"parameters": {
"param1": [
"value1"
],
"param2": [
"value2"
]
Actual:
Response is
[
{
"timestamp": "2017-04-11 19:39:03",
"info": {
"method": "GET",
"path": "/simple",
"headers": {},
"parameters": {}
}
}
]