Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0d62b0cb
Commit
0d62b0cb
authored
Sep 14, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move configuration of TraceEndpoint
See gh-10263
parent
9234801c
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
239 additions
and
46 deletions
+239
-46
TraceEndpointProperties.java
.../actuate/autoconfigure/trace/TraceEndpointProperties.java
+52
-0
TraceWebFilterAutoConfiguration.java
.../autoconfigure/trace/TraceWebFilterAutoConfiguration.java
+6
-8
TraceWebFilterAutoConfigurationTests.java
...configure/trace/TraceWebFilterAutoConfigurationTests.java
+3
-4
Include.java
.../java/org/springframework/boot/actuate/trace/Include.java
+131
-0
WebRequestTraceFilter.java
...ngframework/boot/actuate/trace/WebRequestTraceFilter.java
+15
-6
WebRequestTraceFilterTests.java
...mework/boot/actuate/trace/WebRequestTraceFilterTests.java
+32
-28
No files found.
spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/TraceEndpointProperties.java
0 → 100644
View file @
0d62b0cb
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
trace
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.boot.actuate.trace.Include
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Configuration properties for tracing.
*
* @author Wallace Wadge
* @author Phillip Webb
* @author Venil Noronha
* @author Madhura Bhave
* @author Stephane Nicoll
* @since 1.3.0
*/
@ConfigurationProperties
(
prefix
=
"management.trace"
)
public
class
TraceEndpointProperties
{
/**
* Items to be included in the trace. Defaults to request/response headers (including
* cookies) and errors.
*/
private
Set
<
Include
>
include
=
new
HashSet
<>(
Include
.
defaultIncludes
());
public
Set
<
Include
>
getInclude
()
{
return
this
.
include
;
}
public
void
setInclude
(
Set
<
Include
>
include
)
{
this
.
include
=
include
;
}
}
spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/TraceWebFilterAutoConfiguration.java
View file @
0d62b0cb
...
@@ -19,9 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.trace;
...
@@ -19,9 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.trace;
import
javax.servlet.Servlet
;
import
javax.servlet.Servlet
;
import
javax.servlet.ServletRegistration
;
import
javax.servlet.ServletRegistration
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.actuate.trace.TraceProperties
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.actuate.trace.WebRequestTraceFilter
;
import
org.springframework.boot.actuate.trace.WebRequestTraceFilter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
...
@@ -46,28 +44,28 @@ import org.springframework.web.servlet.DispatcherServlet;
...
@@ -46,28 +44,28 @@ import org.springframework.web.servlet.DispatcherServlet;
@ConditionalOnClass
({
Servlet
.
class
,
DispatcherServlet
.
class
,
ServletRegistration
.
class
})
@ConditionalOnClass
({
Servlet
.
class
,
DispatcherServlet
.
class
,
ServletRegistration
.
class
})
@AutoConfigureAfter
(
TraceRepositoryAutoConfiguration
.
class
)
@AutoConfigureAfter
(
TraceRepositoryAutoConfiguration
.
class
)
@ConditionalOnProperty
(
prefix
=
"management.trace.filter"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
prefix
=
"management.trace.filter"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@EnableConfigurationProperties
(
TraceProperties
.
class
)
@EnableConfigurationProperties
(
Trace
Endpoint
Properties
.
class
)
public
class
TraceWebFilterAutoConfiguration
{
public
class
TraceWebFilterAutoConfiguration
{
private
final
TraceRepository
traceRepository
;
private
final
TraceRepository
traceRepository
;
private
final
Trace
Properties
trace
Properties
;
private
final
Trace
EndpointProperties
endpoint
Properties
;
private
final
ErrorAttributes
errorAttributes
;
private
final
ErrorAttributes
errorAttributes
;
public
TraceWebFilterAutoConfiguration
(
TraceRepository
traceRepository
,
public
TraceWebFilterAutoConfiguration
(
TraceRepository
traceRepository
,
Trace
Properties
trace
Properties
,
Trace
EndpointProperties
endpoint
Properties
,
ObjectProvider
<
ErrorAttributes
>
errorAttributes
)
{
ObjectProvider
<
ErrorAttributes
>
errorAttributes
)
{
this
.
traceRepository
=
traceRepository
;
this
.
traceRepository
=
traceRepository
;
this
.
traceProperties
=
trace
Properties
;
this
.
endpointProperties
=
endpoint
Properties
;
this
.
errorAttributes
=
errorAttributes
.
getIfAvailable
();
this
.
errorAttributes
=
errorAttributes
.
getIfAvailable
();
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
WebRequestTraceFilter
webRequestLoggingFilter
(
BeanFactory
beanFactory
)
{
public
WebRequestTraceFilter
webRequestLoggingFilter
()
{
WebRequestTraceFilter
filter
=
new
WebRequestTraceFilter
(
this
.
traceRepository
,
WebRequestTraceFilter
filter
=
new
WebRequestTraceFilter
(
this
.
traceRepository
,
this
.
traceProperties
);
this
.
endpointProperties
.
getInclude
()
);
if
(
this
.
errorAttributes
!=
null
)
{
if
(
this
.
errorAttributes
!=
null
)
{
filter
.
setErrorAttributes
(
this
.
errorAttributes
);
filter
.
setErrorAttributes
(
this
.
errorAttributes
);
}
}
...
...
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/trace/TraceWebFilterAutoConfigurationTests.java
View file @
0d62b0cb
...
@@ -21,7 +21,6 @@ import java.util.Map;
...
@@ -21,7 +21,6 @@ import java.util.Map;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.trace.TraceProperties
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.actuate.trace.WebRequestTraceFilter
;
import
org.springframework.boot.actuate.trace.WebRequestTraceFilter
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
...
@@ -91,7 +90,7 @@ public class TraceWebFilterAutoConfigurationTests {
...
@@ -91,7 +90,7 @@ public class TraceWebFilterAutoConfigurationTests {
@Bean
@Bean
public
TestWebRequestTraceFilter
testWebRequestTraceFilter
(
public
TestWebRequestTraceFilter
testWebRequestTraceFilter
(
TraceRepository
repository
,
TraceProperties
properties
)
{
TraceRepository
repository
,
Trace
Endpoint
Properties
properties
)
{
return
new
TestWebRequestTraceFilter
(
repository
,
properties
);
return
new
TestWebRequestTraceFilter
(
repository
,
properties
);
}
}
...
@@ -100,8 +99,8 @@ public class TraceWebFilterAutoConfigurationTests {
...
@@ -100,8 +99,8 @@ public class TraceWebFilterAutoConfigurationTests {
static
class
TestWebRequestTraceFilter
extends
WebRequestTraceFilter
{
static
class
TestWebRequestTraceFilter
extends
WebRequestTraceFilter
{
TestWebRequestTraceFilter
(
TraceRepository
repository
,
TestWebRequestTraceFilter
(
TraceRepository
repository
,
TraceProperties
properties
)
{
Trace
Endpoint
Properties
properties
)
{
super
(
repository
,
properties
);
super
(
repository
,
properties
.
getInclude
()
);
}
}
@Override
@Override
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/
TraceProperties
.java
→
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/
Include
.java
View file @
0d62b0cb
...
@@ -17,23 +17,96 @@
...
@@ -17,23 +17,96 @@
package
org
.
springframework
.
boot
.
actuate
.
trace
;
package
org
.
springframework
.
boot
.
actuate
.
trace
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
/**
*
Configuration propertie
s for tracing.
*
Include option
s for tracing.
*
*
* @author Wallace Wadge
* @author Wallace Wadge
* @author Phillip Webb
* @since 2.0.0
* @author Venil Noronha
* @author Madhura Bhave
* @since 1.3.0
*/
*/
@ConfigurationProperties
(
prefix
=
"management.trace"
)
public
enum
Include
{
public
class
TraceProperties
{
/**
* Include request headers.
*/
REQUEST_HEADERS
,
/**
* Include response headers.
*/
RESPONSE_HEADERS
,
/**
* Include "Cookie" in request and "Set-Cookie" in response headers.
*/
COOKIES
,
/**
* Include authorization header (if any).
*/
AUTHORIZATION_HEADER
,
/**
* Include errors (if any).
*/
ERRORS
,
/**
* Include path info.
*/
PATH_INFO
,
/**
* Include the translated path.
*/
PATH_TRANSLATED
,
/**
* Include the context path.
*/
CONTEXT_PATH
,
/**
* Include the user principal.
*/
USER_PRINCIPAL
,
/**
* Include the parameters.
*/
PARAMETERS
,
/**
* Include the query string.
*/
QUERY_STRING
,
/**
* Include the authentication type.
*/
AUTH_TYPE
,
/**
* Include the remote address.
*/
REMOTE_ADDRESS
,
/**
* Include the session ID.
*/
SESSION_ID
,
/**
* Include the remote user.
*/
REMOTE_USER
,
/**
* Include the time taken to service the request in milliseconds.
*/
TIME_TAKEN
;
private
static
final
Set
<
Include
>
DEFAULT_INCLUDES
;
private
static
final
Set
<
Include
>
DEFAULT_INCLUDES
;
...
@@ -48,104 +121,11 @@ public class TraceProperties {
...
@@ -48,104 +121,11 @@ public class TraceProperties {
}
}
/**
/**
*
Items to be included in the trace. Defaults to request/response headers (including
*
Return the default {@link Include}.
*
cookies) and errors
.
*
@return the default include
.
*/
*/
private
Set
<
Include
>
include
=
new
HashSet
<>(
DEFAULT_INCLUDES
);
public
static
Set
<
Include
>
defaultIncludes
()
{
return
DEFAULT_INCLUDES
;
public
Set
<
Include
>
getInclude
()
{
return
this
.
include
;
}
public
void
setInclude
(
Set
<
Include
>
include
)
{
this
.
include
=
include
;
}
/**
* Include options for tracing.
*/
public
enum
Include
{
/**
* Include request headers.
*/
REQUEST_HEADERS
,
/**
* Include response headers.
*/
RESPONSE_HEADERS
,
/**
* Include "Cookie" in request and "Set-Cookie" in response headers.
*/
COOKIES
,
/**
* Include authorization header (if any).
*/
AUTHORIZATION_HEADER
,
/**
* Include errors (if any).
*/
ERRORS
,
/**
* Include path info.
*/
PATH_INFO
,
/**
* Include the translated path.
*/
PATH_TRANSLATED
,
/**
* Include the context path.
*/
CONTEXT_PATH
,
/**
* Include the user principal.
*/
USER_PRINCIPAL
,
/**
* Include the parameters.
*/
PARAMETERS
,
/**
* Include the query string.
*/
QUERY_STRING
,
/**
* Include the authentication type.
*/
AUTH_TYPE
,
/**
* Include the remote address.
*/
REMOTE_ADDRESS
,
/**
* Include the session ID.
*/
SESSION_ID
,
/**
* Include the remote user.
*/
REMOTE_USER
,
/**
* Include the time taken to service the request in milliseconds.
*/
TIME_TAKEN
}
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java
View file @
0d62b0cb
...
@@ -38,7 +38,6 @@ import javax.servlet.http.HttpSession;
...
@@ -38,7 +38,6 @@ import javax.servlet.http.HttpSession;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.actuate.trace.TraceProperties.Include
;
import
org.springframework.boot.web.servlet.error.ErrorAttributes
;
import
org.springframework.boot.web.servlet.error.ErrorAttributes
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
...
@@ -68,16 +67,26 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
...
@@ -68,16 +67,26 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
private
ErrorAttributes
errorAttributes
;
private
ErrorAttributes
errorAttributes
;
private
final
TraceProperties
properti
es
;
private
final
Set
<
Include
>
includ
es
;
/**
/**
* Create a new {@link WebRequestTraceFilter} instance.
* Create a new {@link WebRequestTraceFilter} instance.
* @param repository the trace repository
* @param repository the trace repository
* @param
properties the trace properties
* @param
includes the {@link Include} to apply
*/
*/
public
WebRequestTraceFilter
(
TraceRepository
repository
,
TraceProperties
properti
es
)
{
public
WebRequestTraceFilter
(
TraceRepository
repository
,
Set
<
Include
>
includ
es
)
{
this
.
repository
=
repository
;
this
.
repository
=
repository
;
this
.
properties
=
properties
;
this
.
includes
=
includes
;
}
/**
* Create a new {@link WebRequestTraceFilter} instance with the default
* {@link Include} to apply.
* @param repository the trace repository
* @see Include#defaultIncludes()
*/
public
WebRequestTraceFilter
(
TraceRepository
repository
)
{
this
(
repository
,
Include
.
defaultIncludes
());
}
}
/**
/**
...
@@ -247,7 +256,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
...
@@ -247,7 +256,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
}
}
private
boolean
isIncluded
(
Include
include
)
{
private
boolean
isIncluded
(
Include
include
)
{
return
this
.
properties
.
getInclude
()
.
contains
(
include
);
return
this
.
includes
.
contains
(
include
);
}
}
public
void
setErrorAttributes
(
ErrorAttributes
errorAttributes
)
{
public
void
setErrorAttributes
(
ErrorAttributes
errorAttributes
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/WebRequestTraceFilterTests.java
View file @
0d62b0cb
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment