From 05c5b1225ca34d018c7c30c7998c1b1d34ba4133 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 2 Nov 2022 16:25:37 +0100 Subject: [PATCH] Replace Tag to KeyValues adapter code Closes gh-32876 --- .../web/client/ClientHttpObservationConventionAdapter.java | 6 +----- .../web/client/ClientObservationConventionAdapter.java | 6 +----- .../reactive/ServerRequestObservationConventionAdapter.java | 6 +----- .../servlet/ServerRequestObservationConventionAdapter.java | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientHttpObservationConventionAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientHttpObservationConventionAdapter.java index 5eb017726788..87205527f5e2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientHttpObservationConventionAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientHttpObservationConventionAdapter.java @@ -46,11 +46,7 @@ class ClientHttpObservationConventionAdapter implements ClientRequestObservation public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) { Iterable tags = this.tagsProvider.getTags(context.getUriTemplate(), context.getCarrier(), context.getResponse()); - KeyValues keyValues = KeyValues.empty(); - for (Tag tag : tags) { - keyValues = keyValues.and(tag.getKey(), tag.getValue()); - } - return keyValues; + return KeyValues.of(tags, Tag::getKey, Tag::getValue); } @Override 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 36b29a342674..a36e4d11d229 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 @@ -57,11 +57,7 @@ public boolean supportsContext(Observation.Context context) { public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) { mutateClientRequest(context); Iterable tags = this.tagsProvider.tags(context.getCarrier(), context.getResponse(), context.getError()); - KeyValues keyValues = KeyValues.empty(); - for (Tag tag : tags) { - keyValues = keyValues.and(tag.getKey(), tag.getValue()); - } - return keyValues; + return KeyValues.of(tags, Tag::getKey, Tag::getValue); } private void mutateClientRequest(ClientRequestObservationContext context) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java index 8b2138617c00..d4d347aac1b9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/reactive/ServerRequestObservationConventionAdapter.java @@ -59,11 +59,7 @@ public String getName() { @Override public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) { Iterable tags = this.tagsProvider.httpRequestTags(context.getServerWebExchange(), context.getError()); - KeyValues keyValues = KeyValues.empty(); - for (Tag tag : tags) { - keyValues = keyValues.and(tag.getKey(), tag.getValue()); - } - return keyValues; + return KeyValues.of(tags, Tag::getKey, Tag::getValue); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java index 22f2cd819e27..842b2ec4d145 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/servlet/ServerRequestObservationConventionAdapter.java @@ -66,11 +66,7 @@ public boolean supportsContext(Observation.Context context) { public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) { Iterable tags = this.tagsProvider.getTags(context.getCarrier(), context.getResponse(), getHandler(context), context.getError()); - KeyValues keyValues = KeyValues.empty(); - for (Tag tag : tags) { - keyValues = keyValues.and(tag.getKey(), tag.getValue()); - } - return keyValues; + return KeyValues.of(tags, Tag::getKey, Tag::getValue); } private Object getHandler(ServerRequestObservationContext context) {