Skip to content

Commit

Permalink
Change the description for the uri client request observation metric …
Browse files Browse the repository at this point in the history
…to describe what parts that are removed from the template
  • Loading branch information
Mattias-Sehlstedt committed Dec 18, 2024
1 parent 4b9f173 commit 07bc906
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Instrumentation uses the `org.springframework.http.client.observation.ClientRequ
|===
|Name | Description
|`method` _(required)_|Name of the HTTP request method or `"none"` if not a well-known method.
|`uri` _(required)_|URI template used for HTTP request, or `"none"` if none was provided. Only the path part of the URI is considered.
|`uri` _(required)_|URI template used for HTTP request, or `"none"` if none was provided. The protocol, host and port part of the URI are not considered.
|`client.name` _(required)_|Client name derived from the request URI host.
|`status` _(required)_|HTTP response raw status code, or `"IO_ERROR"` in case of `IOException`, or `"CLIENT_ERROR"` if no response was received.
|`outcome` _(required)_|Outcome of the HTTP client exchange.
Expand Down Expand Up @@ -313,7 +313,7 @@ Instrumentation uses the `org.springframework.http.client.observation.ClientRequ
|===
|Name | Description
|`method` _(required)_|Name of the HTTP request method or `"none"` if the request could not be created.
|`uri` _(required)_|URI template used for HTTP request, or `"none"` if none was provided. Only the path part of the URI is considered.
|`uri` _(required)_|URI template used for HTTP request, or `"none"` if none was provided. The protocol, host and port part of the URI are not considered.
|`client.name` _(required)_|Client name derived from the request URI host.
|`status` _(required)_|HTTP response raw status code, or `"IO_ERROR"` in case of `IOException`, or `"CLIENT_ERROR"` if no response was received.
|`outcome` _(required)_|Outcome of the HTTP client exchange.
Expand Down Expand Up @@ -342,7 +342,7 @@ Instrumentation uses the `org.springframework.web.reactive.function.client.Clien
|===
|Name | Description
|`method` _(required)_|Name of the HTTP request method or `"none"` if not a well-known method.
|`uri` _(required)_|URI template used for HTTP request, or `"none"` if none was provided. Only the path part of the URI is considered.
|`uri` _(required)_|URI template used for HTTP request, or `"none"` if none was provided. The protocol, host and port part of the URI are not considered.
|`client.name` _(required)_|Client name derived from the request URI host.
|`status` _(required)_|HTTP response raw status code, or `"IO_ERROR"` in case of `IOException`, or `"CLIENT_ERROR"` if no response was received.
|`outcome` _(required)_|Outcome of the HTTP client exchange.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String asString() {
/**
* URI template used for HTTP request, or {@value KeyValue#NONE_VALUE} if
* none was provided.
* <p>Only the path part of the URI is considered.
* <p>The protocol, host and port part of the URI are not considered.
*/
URI {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ void addsKeyValuesForRequestWithUriTemplateWithHost() {
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "https://example.org/resource/42"));
}

@Test
void addsKeyValuesForRequestWithUriTemplateWithHostAndQuery() {
ClientRequestObservationContext context = createContext(
new MockClientHttpRequest(HttpMethod.GET, "https://example.org/resource/{id}?queryKey={queryValue}", 42, "Query"), response);
context.setUriTemplate("https://example.org/resource/{id}?queryKey={queryValue}");
assertThat(this.observationConvention.getLowCardinalityKeyValues(context))
.contains(KeyValue.of("exception", "none"), KeyValue.of("method", "GET"), KeyValue.of("uri", "/resource/{id}?queryKey={queryValue}"),
KeyValue.of("status", "200"), KeyValue.of("client.name", "example.org"), KeyValue.of("outcome", "SUCCESS"));
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "https://example.org/resource/42?queryKey=Query"));
}

@Test
void addsKeyValuesForRequestWithUriTemplateWithoutPath() {
ClientRequestObservationContext context = createContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String asString() {
/**
* URI template used for HTTP request, or {@value KeyValue#NONE_VALUE} if
* none was provided.
* <p>Only the path part of the URI is considered.
* <p>The protocol, host and port part of the URI are not considered.
*/
URI {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ void shouldOnlyConsiderPathForUriKeyValue() {
assertThat(this.observationConvention.getLowCardinalityKeyValues(context)).contains(KeyValue.of("uri", "/resource/{id}"));
}

@Test
void shouldKeepQueryParameterForUriKeyValue() {
ClientRequestObservationContext context = createContext(ClientRequest.create(HttpMethod.GET, URI.create("https://example.org/resource/42?queryKey=Query")));
context.setUriTemplate("https://example.org/resource/{id}?queryKey={queryValue}");
assertThat(this.observationConvention.getLowCardinalityKeyValues(context)).contains(KeyValue.of("uri", "/resource/{id}?queryKey={queryValue}"));
}

private ClientRequestObservationContext createContext(ClientRequest.Builder request) {
ClientRequestObservationContext context = new ClientRequestObservationContext(request);
context.setResponse(ClientResponse.create(HttpStatus.OK).build());
Expand Down

0 comments on commit 07bc906

Please sign in to comment.