Auto-detect observability beans in WebHttpHandlerBuilder

This commit ensures that both `ObservationRegsitry` and
`ServerRequestObservationConvention` beans are automatically detected in
the application context if they are unique. This aligns with the
existing behavior for all other builder methods.

Closes gh-31205
This commit is contained in:
Brian Clozel
2023-09-11 21:17:14 +02:00
parent dfd631e662
commit 19588d413d
2 changed files with 46 additions and 1 deletions

View File

@@ -162,6 +162,10 @@ public final class WebHttpHandlerBuilder {
* ordered.
* <li>{@link HttpHandlerDecoratorFactory} [0..N] -- detected by type and
* ordered.
* <li>{@link ObservationRegistry} -- detected by type and
* configured if unique.
* <li>{@link ServerRequestObservationConvention} -- detected by type and
* configured if unique.
* <li>{@link WebSessionManager} [0..1] -- looked up by the name
* {@link #WEB_SESSION_MANAGER_BEAN_NAME}.
* <li>{@link ServerCodecConfigurer} [0..1] -- looked up by the name
@@ -193,6 +197,9 @@ public final class WebHttpHandlerBuilder {
.orderedStream()
.forEach(builder::httpHandlerDecorator);
context.getBeanProvider(ObservationRegistry.class).ifUnique(builder::observationRegistry);
context.getBeanProvider(ServerRequestObservationConvention.class).ifUnique(builder::observationConvention);
try {
builder.sessionManager(
context.getBean(WEB_SESSION_MANAGER_BEAN_NAME, WebSessionManager.class));