Skip to content

Commit 1ad7cc3

Browse files
committed
Reorganize server observability packages
Prior to this commit, the server observability support would create a cycle in Java packages. This commit refactors the current arrangement to solve this by: * "flattening" the reactive HTTP instrumentation; this removes the dependency to the `ServerWebExchange` and `PathPattern` types * moving the `observation` package under `org.springframework.http.server` and `org.springframework.http.server.reactive` See gh-29477
1 parent 91c6fac commit 1ad7cc3

24 files changed

+87
-94
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=6.0.0-SNAPSHOT
1+
version=6.0.0-RC4
22

33
org.gradle.caching=true
44
org.gradle.jvmargs=-Xmx2048m
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation;
17+
package org.springframework.http.server.observation;
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.KeyValues;
2121

2222
import org.springframework.http.HttpStatus;
2323
import org.springframework.http.HttpStatusCode;
24-
import org.springframework.http.observation.ServerHttpObservationDocumentation.HighCardinalityKeyNames;
25-
import org.springframework.http.observation.ServerHttpObservationDocumentation.LowCardinalityKeyNames;
24+
import org.springframework.http.server.observation.ServerHttpObservationDocumentation.HighCardinalityKeyNames;
25+
import org.springframework.http.server.observation.ServerHttpObservationDocumentation.LowCardinalityKeyNames;
2626
import org.springframework.util.StringUtils;
2727

2828
/**

spring-web/src/main/java/org/springframework/http/observation/ServerHttpObservationDocumentation.java renamed to spring-web/src/main/java/org/springframework/http/server/observation/ServerHttpObservationDocumentation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation;
17+
package org.springframework.http.server.observation;
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.docs.KeyName;
@@ -33,9 +33,9 @@
3333
public enum ServerHttpObservationDocumentation implements ObservationDocumentation {
3434

3535
/**
36-
* HTTP exchanges observations for Servlet-based servers.
36+
* HTTP request observations for Servlet-based servers.
3737
*/
38-
HTTP_SERVLET_SERVER_EXCHANGES {
38+
HTTP_SERVLET_SERVER_REQUESTS {
3939
@Override
4040
public Class<? extends ObservationConvention<? extends Observation.Context>> getDefaultConvention() {
4141
return DefaultServerRequestObservationConvention.class;

spring-web/src/main/java/org/springframework/http/observation/ServerRequestObservationContext.java renamed to spring-web/src/main/java/org/springframework/http/server/observation/ServerRequestObservationContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation;
17+
package org.springframework.http.server.observation;
1818

1919
import io.micrometer.observation.transport.RequestReplyReceiverContext;
2020
import jakarta.servlet.http.HttpServletRequest;
@@ -23,10 +23,10 @@
2323
import org.springframework.lang.Nullable;
2424

2525
/**
26-
* Context that holds information for metadata collection during observations
27-
* for {@link ServerHttpObservationDocumentation#HTTP_SERVLET_SERVER_EXCHANGES Servlet HTTP exchanges}.
26+
* Context that holds information for metadata collection regarding
27+
* {@link ServerHttpObservationDocumentation#HTTP_SERVLET_SERVER_REQUESTS Servlet HTTP requests} observations.
2828
* <p>This context also extends {@link RequestReplyReceiverContext} for propagating
29-
* tracing information with the HTTP server exchange.
29+
* tracing information during HTTP request processing.
3030
*
3131
* @author Brian Clozel
3232
* @since 6.0

spring-web/src/main/java/org/springframework/http/observation/ServerRequestObservationConvention.java renamed to spring-web/src/main/java/org/springframework/http/server/observation/ServerRequestObservationConvention.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation;
17+
package org.springframework.http.server.observation;
1818

1919
import io.micrometer.observation.Observation;
2020
import io.micrometer.observation.ObservationConvention;
2121

2222
/**
23-
* Interface for an {@link ObservationConvention} for {@link ServerHttpObservationDocumentation#HTTP_SERVLET_SERVER_EXCHANGES Servlet HTTP exchanges}.
23+
* Interface for an {@link ObservationConvention} for {@link ServerHttpObservationDocumentation#HTTP_SERVLET_SERVER_REQUESTS Servlet HTTP requests}.
2424
*
2525
* @author Brian Clozel
2626
* @since 6.0
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Instrumentation for {@link io.micrometer.observation.Observation observing} HTTP applications.
2+
* Instrumentation for {@link io.micrometer.observation.Observation observing} HTTP server applications.
33
*/
44
@NonNullApi
55
@NonNullFields
6-
package org.springframework.http.observation;
6+
package org.springframework.http.server.observation;
77

88
import org.springframework.lang.NonNullApi;
99
import org.springframework.lang.NonNullFields;
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation.reactive;
17+
package org.springframework.http.server.reactive.observation;
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.KeyValues;
2121

2222
import org.springframework.http.HttpStatus;
2323
import org.springframework.http.HttpStatusCode;
24-
import org.springframework.http.observation.reactive.ServerHttpObservationDocumentation.HighCardinalityKeyNames;
25-
import org.springframework.http.observation.reactive.ServerHttpObservationDocumentation.LowCardinalityKeyNames;
24+
import org.springframework.http.server.reactive.observation.ServerHttpObservationDocumentation.HighCardinalityKeyNames;
25+
import org.springframework.http.server.reactive.observation.ServerHttpObservationDocumentation.LowCardinalityKeyNames;
2626
import org.springframework.util.StringUtils;
27-
import org.springframework.web.util.pattern.PathPattern;
2827

2928
/**
3029
* Default {@link ServerRequestObservationConvention}.
@@ -117,12 +116,12 @@ protected KeyValue status(ServerRequestObservationContext context) {
117116

118117
protected KeyValue uri(ServerRequestObservationContext context) {
119118
if (context.getCarrier() != null) {
120-
PathPattern pattern = context.getPathPattern();
119+
String pattern = context.getPathPattern();
121120
if (pattern != null) {
122-
if (pattern.toString().isEmpty()) {
121+
if (pattern.isEmpty()) {
123122
return URI_ROOT;
124123
}
125-
return KeyValue.of(LowCardinalityKeyNames.URI, pattern.toString());
124+
return KeyValue.of(LowCardinalityKeyNames.URI, pattern);
126125
}
127126
if (context.getResponse() != null && context.getResponse().getStatusCode() != null) {
128127
HttpStatus status = HttpStatus.resolve(context.getResponse().getStatusCode().value());
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation.reactive;
17+
package org.springframework.http.server.reactive.observation;
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.docs.KeyName;
@@ -33,9 +33,9 @@
3333
public enum ServerHttpObservationDocumentation implements ObservationDocumentation {
3434

3535
/**
36-
* HTTP exchanges observations for reactive servers.
36+
* HTTP request observations for reactive servers.
3737
*/
38-
HTTP_REACTIVE_SERVER_EXCHANGES {
38+
HTTP_REACTIVE_SERVER_REQUESTS {
3939
@Override
4040
public Class<? extends ObservationConvention<? extends Observation.Context>> getDefaultConvention() {
4141
return DefaultServerRequestObservationConvention.class;
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,47 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation.reactive;
17+
package org.springframework.http.server.reactive.observation;
18+
19+
import java.util.Collections;
20+
import java.util.Map;
1821

1922
import io.micrometer.observation.transport.RequestReplyReceiverContext;
2023

2124
import org.springframework.http.server.reactive.ServerHttpRequest;
2225
import org.springframework.http.server.reactive.ServerHttpResponse;
2326
import org.springframework.lang.Nullable;
24-
import org.springframework.web.server.ServerWebExchange;
25-
import org.springframework.web.util.pattern.PathPattern;
2627

2728
/**
28-
* Context that holds information for metadata collection during observations
29-
* for {@link ServerHttpObservationDocumentation#HTTP_REACTIVE_SERVER_EXCHANGES reactive HTTP exchanges}.
29+
* Context that holds information for metadata collection regarding
30+
* {@link ServerHttpObservationDocumentation#HTTP_REACTIVE_SERVER_REQUESTS reactive HTTP requests} observations.
3031
* <p>This context also extends {@link RequestReplyReceiverContext} for propagating
31-
* tracing information with the HTTP server exchange.
32+
* tracing information during HTTP request processing.
3233
*
3334
* @author Brian Clozel
3435
* @since 6.0
3536
*/
3637
public class ServerRequestObservationContext extends RequestReplyReceiverContext<ServerHttpRequest, ServerHttpResponse> {
3738

38-
private final ServerWebExchange serverWebExchange;
39+
private final Map<String, Object> attributes;
3940

4041
@Nullable
41-
private PathPattern pathPattern;
42+
private String pathPattern;
4243

4344
private boolean connectionAborted;
4445

45-
public ServerRequestObservationContext(ServerWebExchange exchange) {
46-
super((request, key) -> request.getHeaders().getFirst(key));
47-
this.serverWebExchange = exchange;
48-
setCarrier(exchange.getRequest());
49-
setResponse(exchange.getResponse());
46+
public ServerRequestObservationContext(ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> attributes) {
47+
super((req, key) -> req.getHeaders().getFirst(key));
48+
setCarrier(request);
49+
setResponse(response);
50+
this.attributes = Collections.unmodifiableMap(attributes);
5051
}
5152

5253
/**
53-
* Return the current {@link ServerWebExchange HTTP exchange}.
54+
* Return an immutable map of the current request attributes.
5455
*/
55-
public ServerWebExchange getServerWebExchange() {
56-
return this.serverWebExchange;
56+
public Map<String, Object> getAttributes() {
57+
return this.attributes;
5758
}
5859

5960
/**
@@ -63,7 +64,7 @@ public ServerWebExchange getServerWebExchange() {
6364
* @return the path pattern, or {@code null} if none found
6465
*/
6566
@Nullable
66-
public PathPattern getPathPattern() {
67+
public String getPathPattern() {
6768
return this.pathPattern;
6869
}
6970

@@ -72,7 +73,7 @@ public PathPattern getPathPattern() {
7273
* <p>Path patterns must have a low cardinality for the entire application.
7374
* @param pathPattern the path pattern, for example {@code "/projects/{name}"}.
7475
*/
75-
public void setPathPattern(@Nullable PathPattern pathPattern) {
76+
public void setPathPattern(@Nullable String pathPattern) {
7677
this.pathPattern = pathPattern;
7778
}
7879

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.http.observation.reactive;
17+
package org.springframework.http.server.reactive.observation;
1818

1919
import io.micrometer.observation.Observation;
2020
import io.micrometer.observation.ObservationConvention;
2121

2222
/**
23-
* Interface for an {@link ObservationConvention} for {@link ServerHttpObservationDocumentation#HTTP_REACTIVE_SERVER_EXCHANGES reactive HTTP exchanges}.
23+
* Interface for an {@link ObservationConvention} for {@link ServerHttpObservationDocumentation#HTTP_REACTIVE_SERVER_REQUESTS reactive HTTP requests}.
2424
*
2525
* @author Brian Clozel
2626
* @since 6.0

0 commit comments

Comments
 (0)