Skip to content

Commit b084019

Browse files
Reverse the order of tracing and metrics handlers
Closes gh-32463 Co-authored-by: Jonatan Ivanov <[email protected]>
1 parent 78a64d7 commit b084019

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/TracingObservationHandlerGrouping.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
* {@link ObservationHandlerGrouping} used by {@link ObservationAutoConfiguration} if
3131
* micrometer-tracing is on the classpath.
3232
*
33-
* Groups all {@link MeterObservationHandler} into a
34-
* {@link FirstMatchingCompositeObservationHandler}, and all
35-
* {@link TracingObservationHandler} into a
36-
* {@link FirstMatchingCompositeObservationHandler}. All other handlers are added to the
37-
* {@link ObservationConfig} directly.
33+
* Groups all {@link TracingObservationHandler} into a
34+
* {@link FirstMatchingCompositeObservationHandler}, and {@link MeterObservationHandler}
35+
* into a {@link FirstMatchingCompositeObservationHandler}. All other handlers are added
36+
* to the {@link ObservationConfig} directly.
3837
*
3938
* @author Moritz Halbritter
4039
*/
@@ -45,22 +44,22 @@ public void apply(Collection<ObservationHandler<?>> handlers, ObservationConfig
4544
List<ObservationHandler<?>> meterObservationHandlers = new ArrayList<>();
4645
List<ObservationHandler<?>> tracingObservationHandlers = new ArrayList<>();
4746
for (ObservationHandler<?> handler : handlers) {
48-
if (handler instanceof MeterObservationHandler<?>) {
49-
meterObservationHandlers.add(handler);
50-
}
51-
else if (handler instanceof TracingObservationHandler<?>) {
47+
if (handler instanceof TracingObservationHandler<?>) {
5248
tracingObservationHandlers.add(handler);
5349
}
50+
else if (handler instanceof MeterObservationHandler<?>) {
51+
meterObservationHandlers.add(handler);
52+
}
5453
else {
5554
config.observationHandler(handler);
5655
}
5756
}
58-
if (!meterObservationHandlers.isEmpty()) {
59-
config.observationHandler(new FirstMatchingCompositeObservationHandler(meterObservationHandlers));
60-
}
6157
if (!tracingObservationHandlers.isEmpty()) {
6258
config.observationHandler(new FirstMatchingCompositeObservationHandler(tracingObservationHandlers));
6359
}
60+
if (!meterObservationHandlers.isEmpty()) {
61+
config.observationHandler(new FirstMatchingCompositeObservationHandler(meterObservationHandlers));
62+
}
6463
}
6564

6665
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,18 @@ void autoConfiguresObservationHandlerWhenTracingIsActive() {
144144
assertThat(handlers).hasSize(3);
145145
// Regular handlers are registered first
146146
assertThat(handlers.get(0)).isInstanceOf(CustomObservationHandler.class);
147-
// Multiple MeterObservationHandler are wrapped in
148-
// FirstMatchingCompositeObservationHandler, which calls only the first
149-
// one
150-
assertThat(handlers.get(1)).isInstanceOf(CustomMeterObservationHandler.class);
151-
assertThat(((CustomMeterObservationHandler) handlers.get(1)).getName())
152-
.isEqualTo("customMeterObservationHandler1");
153147
// Multiple TracingObservationHandler are wrapped in
154148
// FirstMatchingCompositeObservationHandler, which calls only the first
155149
// one
156-
assertThat(handlers.get(2)).isInstanceOf(CustomTracingObservationHandler.class);
157-
assertThat(((CustomTracingObservationHandler) handlers.get(2)).getName())
150+
assertThat(handlers.get(1)).isInstanceOf(CustomTracingObservationHandler.class);
151+
assertThat(((CustomTracingObservationHandler) handlers.get(1)).getName())
158152
.isEqualTo("customTracingHandler1");
153+
// Multiple MeterObservationHandler are wrapped in
154+
// FirstMatchingCompositeObservationHandler, which calls only the first
155+
// one
156+
assertThat(handlers.get(2)).isInstanceOf(CustomMeterObservationHandler.class);
157+
assertThat(((CustomMeterObservationHandler) handlers.get(2)).getName())
158+
.isEqualTo("customMeterObservationHandler1");
159159
});
160160
}
161161

0 commit comments

Comments
 (0)