Skip to content

Commit 3817936

Browse files
committed
Declare current observation context as available since 6.0.15
See gh-31609 See gh-31646
1 parent 9bd2be8 commit 3817936

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-2022 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.1
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

@@ -60,6 +62,14 @@ private static void setRequestHeader(@Nullable ClientRequest.Builder request, St
6062
}
6163
}
6264

65+
66+
/**
67+
* Set the URI template used for the current client exchange.
68+
*/
69+
public void setUriTemplate(@Nullable String uriTemplate) {
70+
this.uriTemplate = uriTemplate;
71+
}
72+
6373
/**
6474
* Return the URI template used for the current client exchange, {@code null} if none was used.
6575
*/
@@ -69,10 +79,11 @@ public String getUriTemplate() {
6979
}
7080

7181
/**
72-
* Set the URI template used for the current client exchange.
82+
* Set whether the client aborted the current HTTP exchange.
83+
* @param aborted whether the exchange has been aborted
7384
*/
74-
public void setUriTemplate(@Nullable String uriTemplate) {
75-
this.uriTemplate = uriTemplate;
85+
void setAborted(boolean aborted) {
86+
this.aborted = aborted;
7687
}
7788

7889
/**
@@ -84,11 +95,10 @@ public boolean isAborted() {
8495
}
8596

8697
/**
87-
* Set whether the client aborted the current HTTP exchange.
88-
* @param aborted whether the exchange has been aborted
98+
* Set the client request.
8999
*/
90-
void setAborted(boolean aborted) {
91-
this.aborted = aborted;
100+
public void setRequest(ClientRequest request) {
101+
this.request = request;
92102
}
93103

94104
/**
@@ -99,21 +109,16 @@ public ClientRequest getRequest() {
99109
return this.request;
100110
}
101111

102-
/**
103-
* Set the client request.
104-
*/
105-
public void setRequest(ClientRequest request) {
106-
this.request = request;
107-
}
108112

109113
/**
110114
* Get the current {@link ClientRequestObservationContext observation context}
111115
* from the given request, if available.
112116
* @param request the current client request
113117
* @return the current observation context
114-
* @since 6.1.2
118+
* @since 6.0.15
115119
*/
116120
public static Optional<ClientRequestObservationContext> findCurrent(ClientRequest request) {
117121
return Optional.ofNullable((ClientRequestObservationContext) request.attributes().get(CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE));
118122
}
123+
119124
}

0 commit comments

Comments
 (0)