Reverse the order of tracing and metrics handlers
Closes gh-32463 Co-authored-by: Jonatan Ivanov <jonatan.ivanov@gmail.com>
This commit is contained in:
parent
78a64d7f61
commit
b084019d34
|
@ -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<ObservationHandler<?>> meterObservationHandlers = new ArrayList<>();
|
||||
List<ObservationHandler<?>> 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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue