Skip to content

Commit 24f8015

Browse files
committed
Do not overwrite attributes in ClientObservationConventionAdapter
Prior to this commit, the `ClientObservationConventionAdapter` would overwrite a request builder attribute. This would happen when the request is not fully built when the observation starts. At that point, the tags are built for long task timers, but not for the actual metric. This effectively overrides the correct value of the URI template in the builder. This commit removes this builder update which was invalid in the first place. Fixes gh-40330
1 parent 12e004f commit 24f8015

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-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.
@@ -57,7 +57,7 @@ public boolean supportsContext(Observation.Context context) {
5757
public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) {
5858
ClientRequest request = context.getRequest();
5959
if (request == null) {
60-
request = context.getCarrier().attribute(URI_TEMPLATE_ATTRIBUTE, context.getUriTemplate()).build();
60+
request = context.getCarrier().build();
6161
}
6262
Iterable<Tag> tags = this.tagsProvider.tags(request, context.getResponse(), context.getError());
6363
return KeyValues.of(tags, Tag::getKey, Tag::getValue);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapterTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-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.
@@ -83,6 +83,7 @@ void shouldPushTagsAsLowCardinalityKeyValues() {
8383

8484
@Test
8585
void doesNotFailWithEmptyRequest() {
86+
this.context.setUriTemplate(null);
8687
assertThat(this.convention.getLowCardinalityKeyValues(this.context)).contains(KeyValue.of("status", "200"),
8788
KeyValue.of("outcome", "SUCCESS"), KeyValue.of("uri", "/resource/{name}"),
8889
KeyValue.of("method", "GET"));

0 commit comments

Comments
 (0)