Skip to content

Commit 199a675

Browse files
committed
Declare current observation context as available since 6.0.15
See spring-projectsgh-31609 See spring-projectsgh-31646
1 parent 2f921dd commit 199a675

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,10 +23,12 @@
2323
import org.springframework.lang.Nullable;
2424

2525
/**
26-
* Context that holds information for metadata collection
27-
* during the {@link ClientHttpObservationDocumentation#HTTP_CLIENT_EXCHANGES client HTTP exchanges} observations.
26+
* Context that holds information for metadata collection during the
27+
* {@link ClientHttpObservationDocumentation#HTTP_CLIENT_EXCHANGES client HTTP exchanges} observations.
28+
*
2829
* <p>This context also extends {@link RequestReplySenderContext} for propagating tracing
2930
* information with the HTTP client exchange.
31+
*
3032
* @author Brian Clozel
3133
* @since 6.0
3234
*/
@@ -35,6 +37,7 @@ public class ClientRequestObservationContext extends RequestReplySenderContext<C
3537
@Nullable
3638
private String uriTemplate;
3739

40+
3841
/**
3942
* Create an observation context for {@link ClientHttpRequest} observations.
4043
* @param request the HTTP client request
@@ -50,13 +53,6 @@ private static void setRequestHeader(@Nullable ClientHttpRequest request, String
5053
}
5154
}
5255

53-
/**
54-
* Return the URI template used for the current client exchange, {@code null} if none was used.
55-
*/
56-
@Nullable
57-
public String getUriTemplate() {
58-
return this.uriTemplate;
59-
}
6056

6157
/**
6258
* Set the URI template used for the current client exchange.
@@ -65,4 +61,12 @@ public void setUriTemplate(@Nullable String uriTemplate) {
6561
this.uriTemplate = uriTemplate;
6662
}
6763

64+
/**
65+
* Return the URI template used for the current client exchange, {@code null} if none was used.
66+
*/
67+
@Nullable
68+
public String getUriTemplate() {
69+
return this.uriTemplate;
70+
}
71+
6872
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequestObservationContext.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,11 +23,12 @@
2323
import org.springframework.lang.Nullable;
2424

2525
/**
26-
* Context that holds information for metadata collection
27-
* during the {@link ClientHttpObservationDocumentation#HTTP_REACTIVE_CLIENT_EXCHANGES HTTP client exchange observations}.
26+
* Context that holds information for metadata collection during the
27+
* {@link ClientHttpObservationDocumentation#HTTP_REACTIVE_CLIENT_EXCHANGES HTTP client exchange observations}.
28+
*
2829
* <p>The {@link #getCarrier() tracing context carrier} is a {@link ClientRequest.Builder request builder},
29-
* since the actual request is immutable. For {@code KeyValue} extraction, the {@link #getRequest() actual request}
30-
* should be used instead.
30+
* since the actual request is immutable. For {@code KeyValue} extraction,
31+
* the {@link #getRequest() actual request} should be used instead.
3132
*
3233
* @author Brian Clozel
3334
* @since 6.0
@@ -37,10 +38,11 @@ public class ClientRequestObservationContext extends RequestReplySenderContext<C
3738
/**
3839
* Name of the request attribute holding the {@link ClientRequestObservationContext context}
3940
* for the current observation.
40-
* @since 6.1.2
41+
* @since 6.0.15
4142
*/
4243
public static final String CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE = ClientRequestObservationContext.class.getName();
4344

45+
4446
@Nullable
4547
private String uriTemplate;
4648

@@ -77,6 +79,14 @@ private static void setRequestHeader(@Nullable ClientRequest.Builder request, St
7779
}
7880
}
7981

82+
83+
/**
84+
* Set the URI template used for the current client exchange.
85+
*/
86+
public void setUriTemplate(@Nullable String uriTemplate) {
87+
this.uriTemplate = uriTemplate;
88+
}
89+
8090
/**
8191
* Return the URI template used for the current client exchange, {@code null} if none was used.
8292
*/
@@ -86,10 +96,11 @@ public String getUriTemplate() {
8696
}
8797

8898
/**
89-
* Set the URI template used for the current client exchange.
99+
* Set whether the client aborted the current HTTP exchange.
100+
* @param aborted whether the exchange has been aborted
90101
*/
91-
public void setUriTemplate(@Nullable String uriTemplate) {
92-
this.uriTemplate = uriTemplate;
102+
void setAborted(boolean aborted) {
103+
this.aborted = aborted;
93104
}
94105

95106
/**
@@ -101,11 +112,10 @@ public boolean isAborted() {
101112
}
102113

103114
/**
104-
* Set whether the client aborted the current HTTP exchange.
105-
* @param aborted whether the exchange has been aborted
115+
* Set the client request.
106116
*/
107-
void setAborted(boolean aborted) {
108-
this.aborted = aborted;
117+
public void setRequest(ClientRequest request) {
118+
this.request = request;
109119
}
110120

111121
/**
@@ -116,21 +126,16 @@ public ClientRequest getRequest() {
116126
return this.request;
117127
}
118128

119-
/**
120-
* Set the client request.
121-
*/
122-
public void setRequest(ClientRequest request) {
123-
this.request = request;
124-
}
125129

126130
/**
127131
* Get the current {@link ClientRequestObservationContext observation context}
128132
* from the given request, if available.
129133
* @param request the current client request
130134
* @return the current observation context
131-
* @since 6.1.2
135+
* @since 6.0.15
132136
*/
133137
public static Optional<ClientRequestObservationContext> findCurrent(ClientRequest request) {
134138
return Optional.ofNullable((ClientRequestObservationContext) request.attributes().get(CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE));
135139
}
140+
136141
}

0 commit comments

Comments
 (0)