Restrict "uri" KeyValue for client observations

Prior to this commit, the "uri" KeyValue for low cardinality metadata
would contain the entire uri template given to the HTTP client when
creating the request. This was a breaking change for existing metrics
dashboards, as previous support was removing the protocol, host and port
parts of the URI.
Indeed, this information is available in the "client.name" and
"http.uri" KayValue.

This commit parses and removes the protocol+host+port information from
the uri template for the "uri" KeyValue.

Fixes gh-29885
This commit is contained in:
Brian Clozel
2023-01-30 10:09:45 +01:00
parent b267547fb4
commit 5dfa61eb0b
8 changed files with 45 additions and 7 deletions

View File

@@ -73,6 +73,18 @@ class DefaultClientRequestObservationConventionTests {
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "/resource/42"));
}
@Test
void addsKeyValuesForRequestWithUriTemplateWithHost() {
ClientRequestObservationContext context = createContext(
new MockClientHttpRequest(HttpMethod.GET, "https://example.org/resource/{id}", 42), new MockClientHttpResponse());
context.setUriTemplate("https://example.org/resource/{id}");
assertThat(this.observationConvention.getLowCardinalityKeyValues(context))
.contains(KeyValue.of("exception", "none"), KeyValue.of("method", "GET"), KeyValue.of("uri", "/resource/{id}"),
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"));
}
@Test
void addsKeyValuesForRequestWithoutUriTemplate() {
ClientRequestObservationContext context = createContext(

View File

@@ -88,7 +88,7 @@ class RestTemplateObservationTests {
template.execute("https://example.com/hotels/{hotel}/bookings/{booking}", GET,
null, null, "42", "21");
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "https://example.com/hotels/{hotel}/bookings/{booking}");
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/hotels/{hotel}/bookings/{booking}");
}
@Test
@@ -101,7 +101,7 @@ class RestTemplateObservationTests {
template.execute("https://example.com/hotels/{hotel}/bookings/{booking}", GET,
null, null, vars);
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "https://example.com/hotels/{hotel}/bookings/{booking}");
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/hotels/{hotel}/bookings/{booking}");
}