diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/TracingObservationHandlerGrouping.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/TracingObservationHandlerGrouping.java index 13232ab5b0..a26553208f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/TracingObservationHandlerGrouping.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/TracingObservationHandlerGrouping.java @@ -30,11 +30,10 @@ import io.micrometer.tracing.handler.TracingObservationHandler; * {@link ObservationHandlerGrouping} used by {@link ObservationAutoConfiguration} if * micrometer-tracing is on the classpath. * - * Groups all {@link MeterObservationHandler} into a - * {@link FirstMatchingCompositeObservationHandler}, and all - * {@link TracingObservationHandler} into a - * {@link FirstMatchingCompositeObservationHandler}. All other handlers are added to the - * {@link ObservationConfig} directly. + * Groups all {@link TracingObservationHandler} into a + * {@link FirstMatchingCompositeObservationHandler}, and {@link MeterObservationHandler} + * into a {@link FirstMatchingCompositeObservationHandler}. All other handlers are added + * to the {@link ObservationConfig} directly. * * @author Moritz Halbritter */ @@ -45,22 +44,22 @@ class TracingObservationHandlerGrouping implements ObservationHandlerGrouping { List> meterObservationHandlers = new ArrayList<>(); List> tracingObservationHandlers = new ArrayList<>(); for (ObservationHandler handler : handlers) { - if (handler instanceof MeterObservationHandler) { - meterObservationHandlers.add(handler); - } - else if (handler instanceof TracingObservationHandler) { + if (handler instanceof TracingObservationHandler) { tracingObservationHandlers.add(handler); } + else if (handler instanceof MeterObservationHandler) { + meterObservationHandlers.add(handler); + } else { config.observationHandler(handler); } } - if (!meterObservationHandlers.isEmpty()) { - config.observationHandler(new FirstMatchingCompositeObservationHandler(meterObservationHandlers)); - } if (!tracingObservationHandlers.isEmpty()) { config.observationHandler(new FirstMatchingCompositeObservationHandler(tracingObservationHandlers)); } + if (!meterObservationHandlers.isEmpty()) { + config.observationHandler(new FirstMatchingCompositeObservationHandler(meterObservationHandlers)); + } } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java index b10d7d71d9..fd22f880d9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java @@ -144,18 +144,18 @@ class ObservationAutoConfigurationTests { assertThat(handlers).hasSize(3); // Regular handlers are registered first assertThat(handlers.get(0)).isInstanceOf(CustomObservationHandler.class); - // Multiple MeterObservationHandler are wrapped in - // FirstMatchingCompositeObservationHandler, which calls only the first - // one - assertThat(handlers.get(1)).isInstanceOf(CustomMeterObservationHandler.class); - assertThat(((CustomMeterObservationHandler) handlers.get(1)).getName()) - .isEqualTo("customMeterObservationHandler1"); // Multiple TracingObservationHandler are wrapped in // FirstMatchingCompositeObservationHandler, which calls only the first // one - assertThat(handlers.get(2)).isInstanceOf(CustomTracingObservationHandler.class); - assertThat(((CustomTracingObservationHandler) handlers.get(2)).getName()) + assertThat(handlers.get(1)).isInstanceOf(CustomTracingObservationHandler.class); + assertThat(((CustomTracingObservationHandler) handlers.get(1)).getName()) .isEqualTo("customTracingHandler1"); + // Multiple MeterObservationHandler are wrapped in + // FirstMatchingCompositeObservationHandler, which calls only the first + // one + assertThat(handlers.get(2)).isInstanceOf(CustomMeterObservationHandler.class); + assertThat(((CustomMeterObservationHandler) handlers.get(2)).getName()) + .isEqualTo("customMeterObservationHandler1"); }); }