From 24f80154d4da6d894aee30d43f31df995fc62187 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 12 Apr 2024 16:31:02 +0200 Subject: [PATCH] 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 --- .../web/client/ClientObservationConventionAdapter.java | 4 ++-- .../web/client/ClientObservationConventionAdapterTests.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapter.java index 0f3230a5bf8..85d8cb25dac 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ class ClientObservationConventionAdapter implements ClientRequestObservationConv public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) { ClientRequest request = context.getRequest(); if (request == null) { - request = context.getCarrier().attribute(URI_TEMPLATE_ATTRIBUTE, context.getUriTemplate()).build(); + request = context.getCarrier().build(); } Iterable tags = this.tagsProvider.tags(request, context.getResponse(), context.getError()); return KeyValues.of(tags, Tag::getKey, Tag::getValue); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapterTests.java index cd73e29efba..d4560ed1040 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,6 +83,7 @@ class ClientObservationConventionAdapterTests { @Test void doesNotFailWithEmptyRequest() { + this.context.setUriTemplate(null); assertThat(this.convention.getLowCardinalityKeyValues(this.context)).contains(KeyValue.of("status", "200"), KeyValue.of("outcome", "SUCCESS"), KeyValue.of("uri", "/resource/{name}"), KeyValue.of("method", "GET"));