Skip to content

Commit d69d997

Browse files
committed
Merge branch '6.1.x'
2 parents 80b7215 + 47f7e44 commit d69d997

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
4343

4444
private static final String DEFAULT_NAME = "http.client.requests";
4545

46-
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+/");
46+
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+");
4747

4848
private static final KeyValue URI_NONE = KeyValue.of(LowCardinalityKeyNames.URI, KeyValue.NONE_VALUE);
4949

spring-web/src/test/java/org/springframework/http/client/observation/DefaultClientRequestObservationConventionTests.java

+11-1
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.
@@ -88,6 +88,16 @@ void addsKeyValuesForRequestWithUriTemplateWithHost() {
8888
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "https://example.org/resource/42"));
8989
}
9090

91+
@Test
92+
void addsKeyValuesForRequestWithUriTemplateWithoutPath() {
93+
ClientRequestObservationContext context = createContext(
94+
new MockClientHttpRequest(HttpMethod.GET, "https://example.org"), response);
95+
context.setUriTemplate("https://example.org");
96+
assertThat(this.observationConvention.getLowCardinalityKeyValues(context))
97+
.contains(KeyValue.of("exception", "none"), KeyValue.of("method", "GET"), KeyValue.of("uri", "/"),
98+
KeyValue.of("status", "200"), KeyValue.of("client.name", "example.org"), KeyValue.of("outcome", "SUCCESS"));
99+
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "https://example.org"));
100+
}
91101

92102
@Test
93103
void addsKeyValuesForRequestWithoutUriTemplate() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO
4343

4444
private static final String ROOT_PATH = "/";
4545

46-
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+/");
46+
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+");
4747

4848
private static final KeyValue URI_NONE = KeyValue.of(LowCardinalityKeyNames.URI, KeyValue.NONE_VALUE);
4949

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestObservationConventionTests.java

+14-1
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.
@@ -91,6 +91,19 @@ void shouldAddKeyValuesForRequestWithUriTemplate() {
9191
.contains(KeyValue.of("http.url", "/resource/42"));
9292
}
9393

94+
@Test
95+
void shouldAddKeyValuesForRequestWithUriTemplateNoPath() {
96+
ClientRequest.Builder request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.org"))
97+
.attribute(WebClient.class.getName() + ".uriTemplate", "https://example.org");
98+
ClientRequestObservationContext context = createContext(request);
99+
context.setUriTemplate("https://example.org");
100+
assertThat(this.observationConvention.getLowCardinalityKeyValues(context))
101+
.contains(KeyValue.of("exception", "none"), KeyValue.of("method", "GET"), KeyValue.of("uri", "/"),
102+
KeyValue.of("status", "200"), KeyValue.of("client.name", "example.org"), KeyValue.of("outcome", "SUCCESS"));
103+
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).hasSize(1)
104+
.contains(KeyValue.of("http.url", "https://example.org"));
105+
}
106+
94107
@Test
95108
void shouldAddKeyValuesForRequestWithoutUriTemplate() {
96109
ClientRequestObservationContext context = createContext(ClientRequest.create(HttpMethod.GET, URI.create("/resource/42")));

0 commit comments

Comments
 (0)