diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java index d4d347aac1b9..d040ecba3206 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java @@ -24,8 +24,14 @@ import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider; import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsContributor; import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsProvider; -import org.springframework.http.observation.reactive.ServerRequestObservationContext; -import org.springframework.http.observation.reactive.ServerRequestObservationConvention; +import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; +import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention; +import org.springframework.web.server.adapter.DefaultServerWebExchange; +import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver; +import org.springframework.web.server.i18n.LocaleContextResolver; +import org.springframework.web.server.session.DefaultWebSessionManager; +import org.springframework.web.server.session.WebSessionManager; /** * Adapter class that applies {@link WebFluxTagsProvider} tags as a @@ -37,6 +43,12 @@ @Deprecated(since = "3.0.0", forRemoval = true) class ServerRequestObservationConventionAdapter implements ServerRequestObservationConvention { + private final WebSessionManager webSessionManager = new DefaultWebSessionManager(); + + private final ServerCodecConfigurer serverCodecConfigurer = ServerCodecConfigurer.create(); + + private final LocaleContextResolver localeContextResolver = new AcceptHeaderLocaleContextResolver(); + private final String name; private final WebFluxTagsProvider tagsProvider; @@ -58,7 +70,10 @@ public String getName() { @Override public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) { - Iterable tags = this.tagsProvider.httpRequestTags(context.getServerWebExchange(), context.getError()); + DefaultServerWebExchange serverWebExchange = new DefaultServerWebExchange(context.getCarrier(), + context.getResponse(), this.webSessionManager, this.serverCodecConfigurer, this.localeContextResolver); + serverWebExchange.getAttributes().putAll(context.getAttributes()); + Iterable tags = this.tagsProvider.httpRequestTags(serverWebExchange, context.getError()); return KeyValues.of(tags, Tag::getKey, Tag::getValue); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/WebFluxObservationAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/WebFluxObservationAutoConfiguration.java index c7af8e8096de..85318606c4dc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/WebFluxObservationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/WebFluxObservationAutoConfiguration.java @@ -43,8 +43,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; -import org.springframework.http.observation.reactive.DefaultServerRequestObservationConvention; -import org.springframework.http.observation.reactive.ServerRequestObservationConvention; +import org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention; +import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention; import org.springframework.web.filter.reactive.ServerHttpObservationFilter; /** @@ -85,11 +85,11 @@ public ServerHttpObservationFilter webfluxObservationFilter(ObservationRegistry String name = (observationName != null) ? observationName : metricName; WebFluxTagsProvider tagsProvider = tagConfigurer.getIfAvailable(); List tagsContributors = contributorsProvider.orderedStream().toList(); - ServerRequestObservationConvention convention = extracted(name, tagsProvider, tagsContributors); + ServerRequestObservationConvention convention = createConvention(name, tagsProvider, tagsContributors); return new ServerHttpObservationFilter(registry, convention); } - private ServerRequestObservationConvention extracted(String name, WebFluxTagsProvider tagsProvider, + private ServerRequestObservationConvention createConvention(String name, WebFluxTagsProvider tagsProvider, List tagsContributors) { if (tagsProvider != null) { return new ServerRequestObservationConventionAdapter(name, tagsProvider); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java index 842b2ec4d145..df52cbca7407 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java @@ -25,8 +25,8 @@ import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider; import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsContributor; import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsProvider; -import org.springframework.http.observation.ServerRequestObservationContext; -import org.springframework.http.observation.ServerRequestObservationConvention; +import org.springframework.http.server.observation.ServerRequestObservationContext; +import org.springframework.http.server.observation.ServerRequestObservationConvention; import org.springframework.util.Assert; import org.springframework.web.servlet.HandlerMapping; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/WebMvcObservationAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/WebMvcObservationAutoConfiguration.java index 0c34fd27c7b3..f20f75db0cd4 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/WebMvcObservationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/WebMvcObservationAutoConfiguration.java @@ -46,8 +46,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; -import org.springframework.http.observation.DefaultServerRequestObservationConvention; -import org.springframework.http.observation.ServerRequestObservationConvention; +import org.springframework.http.server.observation.DefaultServerRequestObservationConvention; +import org.springframework.http.server.observation.ServerRequestObservationConvention; import org.springframework.web.filter.ServerHttpObservationFilter; import org.springframework.web.servlet.DispatcherServlet; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapterTests.java index 24f6fc64ce66..9d32817dc80c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapterTests.java @@ -16,13 +16,15 @@ package org.springframework.boot.actuate.autoconfigure.observation.web.reactive; +import java.util.Map; + import io.micrometer.common.KeyValue; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider; -import org.springframework.http.observation.reactive.ServerRequestObservationContext; +import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; -import org.springframework.mock.web.server.MockServerWebExchange; +import org.springframework.mock.http.server.reactive.MockServerHttpResponse; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.util.pattern.PathPatternParser; @@ -39,12 +41,6 @@ class ServerRequestObservationConventionAdapterTests { private static final String TEST_METRIC_NAME = "test.metric.name"; - private final MockServerHttpRequest request = MockServerHttpRequest.get("/resource/test").build(); - - private final MockServerWebExchange serverWebExchange = MockServerWebExchange.builder(this.request).build(); - - private final ServerRequestObservationContext context = new ServerRequestObservationContext(this.serverWebExchange); - private final ServerRequestObservationConventionAdapter convention = new ServerRequestObservationConventionAdapter( TEST_METRIC_NAME, new DefaultWebFluxTagsProvider()); @@ -55,9 +51,12 @@ void shouldUseConfiguredName() { @Test void shouldPushTagsAsLowCardinalityKeyValues() { - this.serverWebExchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, - PathPatternParser.defaultInstance.parse("/resource/{name}")); - assertThat(this.convention.getLowCardinalityKeyValues(this.context)).contains(KeyValue.of("status", "200"), + MockServerHttpRequest request = MockServerHttpRequest.get("/resource/test").build(); + MockServerHttpResponse response = new MockServerHttpResponse(); + ServerRequestObservationContext context = new ServerRequestObservationContext(request, response, + Map.of(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, + PathPatternParser.defaultInstance.parse("/resource/{name}"))); + assertThat(this.convention.getLowCardinalityKeyValues(context)).contains(KeyValue.of("status", "200"), KeyValue.of("outcome", "SUCCESS"), KeyValue.of("uri", "/resource/{name}"), KeyValue.of("method", "GET")); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapterTests.java index 4309e009d5b2..e20d4cfef502 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapterTests.java @@ -28,7 +28,7 @@ import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider; import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsContributor; -import org.springframework.http.observation.ServerRequestObservationContext; +import org.springframework.http.server.observation.ServerRequestObservationContext; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.web.servlet.HandlerMapping; diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/DefaultWebFluxTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/DefaultWebFluxTagsProvider.java index 04a7af9c36a7..ef319dc065ad 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/DefaultWebFluxTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/DefaultWebFluxTagsProvider.java @@ -31,7 +31,7 @@ * @author Andy Wilkinson * @since 2.0.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} + * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention} */ @Deprecated(since = "3.0.0", forRemoval = true) @SuppressWarnings("removal") diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java index 756dd7660ab7..ecada43258a4 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java @@ -41,7 +41,7 @@ * @author Brian Clozel * @since 2.0.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} + * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention} */ @Deprecated(since = "3.0.0", forRemoval = true) public final class WebFluxTags { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsContributor.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsContributor.java index 280fcc3f9065..6bd9958dfca3 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsContributor.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsContributor.java @@ -27,7 +27,7 @@ * @author Andy Wilkinson * @since 2.3.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} + * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention} */ @FunctionalInterface @Deprecated(since = "3.0.0", forRemoval = true) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsProvider.java index 48aaf34078c1..081c9598cc89 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsProvider.java @@ -27,7 +27,7 @@ * @author Andy Wilkinson * @since 2.0.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.reactive.ServerRequestObservationConvention} + * {@link org.springframework.http.server.reactive.observation.ServerRequestObservationConvention} */ @FunctionalInterface @Deprecated(since = "3.0.0", forRemoval = true) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java index 150aa9389709..ac50670ca326 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java @@ -30,7 +30,7 @@ * @author Jon Schneider * @since 2.0.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.ServerRequestObservationConvention} + * {@link org.springframework.http.server.observation.ServerRequestObservationConvention} */ @Deprecated(since = "3.0.0", forRemoval = true) @SuppressWarnings("removal") diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java index 8f4f3ef09b52..db5c1f0e49c5 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java @@ -38,7 +38,7 @@ * @author Michael McFadyen * @since 2.0.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.ServerRequestObservationConvention} + * {@link org.springframework.http.server.observation.ServerRequestObservationConvention} */ @Deprecated(since = "3.0.0", forRemoval = true) public final class WebMvcTags { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsContributor.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsContributor.java index 3355c22e2664..f27b2115af67 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsContributor.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsContributor.java @@ -28,7 +28,7 @@ * @author Andy Wilkinson * @since 2.3.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.ServerRequestObservationConvention} + * {@link org.springframework.http.server.observation.ServerRequestObservationConvention} */ @Deprecated(since = "3.0.0", forRemoval = true) public interface WebMvcTagsContributor { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java index 630af5076f1e..09206f727b1b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java @@ -28,7 +28,7 @@ * @author Andy Wilkinson * @since 2.0.0 * @deprecated since 3.0.0 for removal in 3.2.0 in favor of - * {@link org.springframework.http.observation.ServerRequestObservationConvention} + * {@link org.springframework.http.server.observation.ServerRequestObservationConvention} */ @Deprecated(since = "3.0.0", forRemoval = true) public interface WebMvcTagsProvider { diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 02d4dc2af0c3..f0e88636ef29 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1357,7 +1357,7 @@ bom { ] } } - library("Spring Framework", "6.0.0-RC4") { + library("Spring Framework", "6.0.0-SNAPSHOT") { group("org.springframework") { imports = [ "spring-framework-bom"