Contribute "uri" KeyValue for "/" client requests
Prior to this commit, client HTTP requests performed by `WebClient` could miss the "uri" KeyValue for simple "/" requests. This can happen when the baseUri is configured for the client with a host and a root base path like "https://example.org/"; given the nature of the `WebClient` API, in these cases, one can perform requests like this: ``` WebClient client = WebClient.builder() .observationRegistry(registry) .baseUrl("https://example.org/") .build(); String response = client.get().retrieve().bodyToMono(String.class).block(); ``` Such a call would contribute a `"none"` value for the `"uri"` KeyValue. While only templates should be allowed for this keyvalue, we can assume that requests to `"/"` should be recorded anyway and won't cause cardinality explosion. Fixes gh-29879
This commit is contained in:
@@ -107,6 +107,13 @@ class DefaultClientRequestObservationConventionTests {
|
||||
assertThat(this.observationConvention.getLowCardinalityKeyValues(context)).contains(KeyValue.of("client.name", "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAddRootUriEvenIfTemplateMissing() {
|
||||
ClientRequestObservationContext context = createContext(ClientRequest.create(HttpMethod.GET, URI.create("https://example.org/")));
|
||||
context.setRequest(context.getCarrier().build());
|
||||
assertThat(this.observationConvention.getLowCardinalityKeyValues(context)).contains(KeyValue.of("uri", "/"));
|
||||
}
|
||||
|
||||
private ClientRequestObservationContext createContext(ClientRequest.Builder request) {
|
||||
ClientRequestObservationContext context = new ClientRequestObservationContext();
|
||||
context.setCarrier(request);
|
||||
|
||||
Reference in New Issue
Block a user