You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move reactive server instrumentation out of WebFilter
Prior to this commit, the Observation instrumentation for Reactive
server applications was implemented with a `WebFilter`. This allowed to
record observations and set up a tracing context for the controller
handlers.
The limitation of this approach is that all processing happening at a
lower level is not aware of any observation. Here, the
`HttpWebHandlerAdapter` handles several interesting aspects:
* logging of HTTP requests and responses at the TRACE level
* logging of client disconnect errors
* handling of unresolved errors
With the current instrumentation, these logging statements will miss the
tracing context information. As a result, this commit deprecates the
`ServerHttpObservationFilter` in favor of a more direct instrumentation
of the `HttpWebHandlerAdapter`. This enables a more precise
instrumentattion and allows to set up the current observation earlier in
the reactor context: log statements will now contain the relevant
information.
Fixesgh-30013
Copy file name to clipboardExpand all lines: framework-docs/modules/ROOT/pages/integration/observability.adoc
+7-3
Original file line number
Diff line number
Diff line change
@@ -121,11 +121,15 @@ By default, the following `KeyValues` are created:
121
121
[[observability.http-server.reactive]]
122
122
=== Reactive applications
123
123
124
-
Applications need to configure the `org.springframework.web.filter.reactive.ServerHttpObservationFilter` reactive `WebFilter` in their application.
124
+
Applications need to configure the `WebHttpHandlerBuilder` with a `MeterRegistry` to enable server instrumentation.
125
+
This can be done on the `WebHttpHandlerBuilder`, as follows:
126
+
127
+
include::code:HttpHandlerConfiguration[]
128
+
125
129
It is using the `org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention` by default, backed by the `ServerRequestObservationContext`.
126
130
127
-
This will only record an observation as an error if the `Exception` has not been handled by the web Framework and has bubbled up to the `WebFilter`.
128
-
Typically, all exceptions handled by Spring WebFlux's `@ExceptionHandler` and xref:web/webflux/ann-rest-exceptions.adoc[`ProblemDetail` support] will not be recorded with the observation.
131
+
This will only record an observation as an error if the `Exception` has not been handled by an application Controller.
132
+
Typically, all exceptions handled by Spring WebFlux's `@ExceptionHandler` and <<web.adoc#webflux-ann-rest-exceptions,`ProblemDetail` support>> will not be recorded with the observation.
129
133
You can, at any point during request processing, set the error field on the `ObservationContext` yourself:
Copy file name to clipboardExpand all lines: framework-docs/src/main/java/org/springframework/docs/integration/observability/httpserver/reactive/UserController.java
Copy file name to clipboardExpand all lines: spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java
0 commit comments