Package org.springframework.web.filter
Class ServerHttpObservationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.web.filter.ServerHttpObservationFilter
- All Implemented Interfaces:
Filter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.EnvironmentAware,org.springframework.core.env.EnvironmentCapable,ServletContextAware
Filter that creates observations
for HTTP exchanges. This collects information about the execution time and
information gathered from the ServerRequestObservationContext.
Web Frameworks can fetch the current context
as a request attribute and contribute
additional information to it.
The configured ServerRequestObservationConvention will use this context to collect
metadata and attach it to the observation.
- Since:
- 6.0
- Author:
- Brian Clozel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the request attribute holding thecontextfor the current observation.Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
ConstructorsConstructorDescriptionServerHttpObservationFilter(io.micrometer.observation.ObservationRegistry observationRegistry) Create anHttpRequestsObservationFilterthat records observations against the givenObservationRegistry.ServerHttpObservationFilter(io.micrometer.observation.ObservationRegistry observationRegistry, ServerRequestObservationConvention observationConvention) Create anHttpRequestsObservationFilterthat records observations against the givenObservationRegistrywith a custom convention. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) Same contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread.findObservationContext(HttpServletRequest request) Get the currentobservation contextfrom the given request, if available.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE
Name of the request attribute holding thecontextfor the current observation.
-
-
Constructor Details
-
ServerHttpObservationFilter
public ServerHttpObservationFilter(io.micrometer.observation.ObservationRegistry observationRegistry) Create anHttpRequestsObservationFilterthat records observations against the givenObservationRegistry. The defaultconventionwill be used.- Parameters:
observationRegistry- the registry to use for recording observations
-
ServerHttpObservationFilter
public ServerHttpObservationFilter(io.micrometer.observation.ObservationRegistry observationRegistry, ServerRequestObservationConvention observationConvention) Create anHttpRequestsObservationFilterthat records observations against the givenObservationRegistrywith a custom convention.- Parameters:
observationRegistry- the registry to use for recording observationsobservationConvention- the convention to use for all recorded observations
-
-
Method Details
-
findObservationContext
public static Optional<ServerRequestObservationContext> findObservationContext(HttpServletRequest request) Get the currentobservation contextfrom the given request, if available.- Parameters:
request- the current request- Returns:
- the current observation context
-
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException Description copied from class:OncePerRequestFilterSame contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread. SeeOncePerRequestFilter.shouldNotFilterAsyncDispatch()for details.Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
- Specified by:
doFilterInternalin classOncePerRequestFilter- Throws:
ServletExceptionIOException
-