From 2d318e9581c756eb9b986840e1b69450d15c0507 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 7 Feb 2024 10:42:40 +0100 Subject: [PATCH] Updated levels --- .../java/io/micrometer/observation/Level.java | 2 +- .../micrometer/observation/Observation.java | 52 ++++--------------- .../observation/ObservationRegistry.java | 10 ++-- .../observation/ObservationTests.java | 4 +- 4 files changed, 18 insertions(+), 50 deletions(-) diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/Level.java b/micrometer-observation/src/main/java/io/micrometer/observation/Level.java index 91c893811b..fd215f4e3f 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/Level.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/Level.java @@ -23,6 +23,6 @@ */ public enum Level { - ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF + FULL, DETAILED, BASIC, OFF } diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java b/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java index a7586fd29f..f0c0dc4701 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java @@ -1551,7 +1551,7 @@ default T getOrDefault(Object key, Supplier defaultObjectSupplier) { * @return observation level */ default Level getObservationLevel() { - return Level.ALL; + return Level.FULL; } } @@ -1608,59 +1608,27 @@ public Level getLevel() { } /** - * Sets {@link Level#ALL} for observation of the given classs. + * Sets {@link Level#FULL} for observation of the given classs. * @return observation level */ - public static ObservationLevel all() { - return new ObservationLevel(Level.ALL); + public static ObservationLevel full() { + return new ObservationLevel(Level.FULL); } /** - * Sets {@link Level#TRACE} for observation of the given classs. + * Sets {@link Level#BASIC} for observation of the given classs. * @return observation level */ - public static ObservationLevel trace() { - return new ObservationLevel(Level.TRACE); + public static ObservationLevel basic() { + return new ObservationLevel(Level.BASIC); } /** - * Sets {@link Level#DEBUG} for observation of the given classs. + * Sets {@link Level#DETAILED} for observation of the given classs. * @return observation level */ - public static ObservationLevel debug() { - return new ObservationLevel(Level.DEBUG); - } - - /** - * Sets {@link Level#INFO} for observation of the given classs. - * @return observation level - */ - public static ObservationLevel info() { - return new ObservationLevel(Level.INFO); - } - - /** - * Sets {@link Level#WARN} for observation of the given classs. - * @return observation level - */ - public static ObservationLevel warn() { - return new ObservationLevel(Level.WARN); - } - - /** - * Sets {@link Level#ERROR} for observation of the given classs. - * @return observation level - */ - public static ObservationLevel error() { - return new ObservationLevel(Level.ERROR); - } - - /** - * Sets {@link Level#FATAL} for observation of the given classs. - * @return observation level - */ - public static ObservationLevel fatal() { - return new ObservationLevel(Level.FATAL); + public static ObservationLevel detailed() { + return new ObservationLevel(Level.DETAILED); } /** diff --git a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationRegistry.java b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationRegistry.java index dd129b9a2e..86b531c31e 100644 --- a/micrometer-observation/src/main/java/io/micrometer/observation/ObservationRegistry.java +++ b/micrometer-observation/src/main/java/io/micrometer/observation/ObservationRegistry.java @@ -154,19 +154,19 @@ public ObservationConfig observationConvention(GlobalObservationConvention ob } /** - * Sets an observation level for the given package name. - * @param packageName observation package name + * Sets an observation level for the given observation name. + * @param observationName observation name * @param level observation level * @return This configuration instance */ - public ObservationConfig observationLevel(String packageName, Level level) { - this.observationLevels.put(packageName, level); + public ObservationConfig observationLevel(String observationName, Level level) { + this.observationLevels.put(observationName, level); return this; } /** * Sets observation levels. - * @param levels observation levels (package to level mappings) + * @param levels observation levels (observation name to level mappings) * @return This configuration instance */ public ObservationConfig observationLevels(Map levels) { diff --git a/micrometer-observation/src/test/java/io/micrometer/observation/ObservationTests.java b/micrometer-observation/src/test/java/io/micrometer/observation/ObservationTests.java index 301aaab24b..e1209b10d1 100644 --- a/micrometer-observation/src/test/java/io/micrometer/observation/ObservationTests.java +++ b/micrometer-observation/src/test/java/io/micrometer/observation/ObservationTests.java @@ -79,9 +79,9 @@ void notMatchingObservationPredicateShouldResultInNoopObservation() { void notMatchingObservationLevelShouldResultInPassthroughObservation() { registry.observationConfig().observationHandler(context -> true); registry.observationConfig().observationPredicate((s, context) -> true); - registry.observationConfig().observationLevel("foo", Level.ERROR); + registry.observationConfig().observationLevel("foo", Level.BASIC); - Observation observation = Observation.createNotStarted("foo", ObservationLevel.debug(), registry); + Observation observation = Observation.createNotStarted("foo", ObservationLevel.detailed(), registry); assertThat(observation).isInstanceOf(PassthroughNoopObservation.class); }