1414import java .util .Arrays ;
1515import java .util .List ;
1616import java .util .Locale ;
17- import java .util .function .BiFunction ;
18- import java .util .function .Function ;
1917import java .util .stream .Collectors ;
2018import javax .annotation .Nullable ;
2119
@@ -59,11 +57,11 @@ public static boolean getBoolean(String propertyName, boolean defaultValue) {
5957 */
6058 public static boolean getBoolean (
6159 OpenTelemetry openTelemetry , boolean defaultValue , String ... propertyName ) {
62- return getDeclarativeConfigOrFallback (
63- openTelemetry ,
64- propertyName ,
65- ( node , key ) -> node . getBoolean ( key , defaultValue ),
66- ( key ) -> getBoolean (key , defaultValue ) );
60+ DeclarativeConfigProperties node = getDeclarativeConfigNode ( openTelemetry , propertyName );
61+ if ( node != null ) {
62+ return node . getBoolean ( leaf ( propertyName ), defaultValue );
63+ }
64+ return getBoolean (toSystemProperty ( propertyName ) , defaultValue );
6765 }
6866
6967 /**
@@ -86,8 +84,8 @@ public static int getInt(String propertyName, int defaultValue) {
8684 * Returns the string value of the given property name from system properties and environment
8785 * variables.
8886 *
89- * <p>It's recommended to use {@link #getString(OpenTelemetry, String...)} instead to
90- * support Declarative Config.
87+ * <p>It's recommended to use {@link #getString(OpenTelemetry, String...)} instead to support
88+ * Declarative Config.
9189 */
9290 @ Nullable
9391 public static String getString (String propertyName ) {
@@ -104,8 +102,11 @@ public static String getString(String propertyName) {
104102 */
105103 @ Nullable
106104 public static String getString (OpenTelemetry openTelemetry , String ... propertyName ) {
107- return getDeclarativeConfigOrFallback (
108- openTelemetry , propertyName , (node , key ) -> node .getString (key ), (key ) -> getString (key ));
105+ DeclarativeConfigProperties node = getDeclarativeConfigNode (openTelemetry , propertyName );
106+ if (node != null ) {
107+ return node .getString (leaf (propertyName ));
108+ }
109+ return getString (toSystemProperty (propertyName ));
109110 }
110111
111112 /**
@@ -127,17 +128,15 @@ public static String getStringOrFallback(
127128 */
128129 public static List <String > getList (
129130 OpenTelemetry openTelemetry , List <String > defaultValue , String ... propertyName ) {
130- return getDeclarativeConfigOrFallback (
131- openTelemetry ,
132- propertyName ,
133- (node , key ) -> node .getScalarList (key , String .class , defaultValue ),
134- (key ) -> {
135- String value = getString (key );
136- if (value == null ) {
137- return defaultValue ;
138- }
139- return filterBlanksAndNulls (value .split ("," ));
140- });
131+ DeclarativeConfigProperties node = getDeclarativeConfigNode (openTelemetry , propertyName );
132+ if (node != null ) {
133+ return node .getScalarList (leaf (propertyName ), String .class , defaultValue );
134+ }
135+ String value = getString (toSystemProperty (propertyName ));
136+ if (value == null ) {
137+ return defaultValue ;
138+ }
139+ return filterBlanksAndNulls (value .split ("," ));
141140 }
142141
143142 /** Returns true if the given OpenTelemetry instance supports Declarative Config. */
@@ -156,16 +155,8 @@ private static String toEnvVarName(String propertyName) {
156155 return propertyName .toUpperCase (Locale .ROOT ).replace ('-' , '_' ).replace ('.' , '_' );
157156 }
158157
159- private static <T > T getDeclarativeConfigOrFallback (
160- OpenTelemetry openTelemetry ,
161- String [] propertyName ,
162- BiFunction <DeclarativeConfigProperties , String , T > getter ,
163- Function <String , T > fallback ) {
164- DeclarativeConfigProperties node = getDeclarativeConfigNode (openTelemetry , propertyName );
165- if (node != null ) {
166- return getter .apply (node , propertyName [propertyName .length - 1 ]);
167- }
168- return fallback .apply (toSystemProperty (propertyName ));
158+ private static String leaf (String [] propertyName ) {
159+ return propertyName [propertyName .length - 1 ];
169160 }
170161
171162 @ Nullable
0 commit comments