|
6 | 6 | package io.opentelemetry.instrumentation.api.internal; |
7 | 7 |
|
8 | 8 | import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty; |
| 9 | +import static java.util.Objects.requireNonNull; |
9 | 10 |
|
10 | 11 | import io.opentelemetry.api.OpenTelemetry; |
11 | 12 | import io.opentelemetry.api.incubator.ExtendedOpenTelemetry; |
@@ -87,18 +88,29 @@ public static String getString(String propertyName) { |
87 | 88 | return System.getenv(toEnvVarName(propertyName)); |
88 | 89 | } |
89 | 90 |
|
90 | | - private static String getString(String propertyName, String defaultValue) { |
91 | | - String strValue = getString(propertyName); |
92 | | - return strValue == null ? defaultValue : strValue; |
93 | | - } |
94 | | - |
95 | 91 | public static String getString( |
96 | 92 | OpenTelemetry openTelemetry, String defaultValue, String... propertyName) { |
97 | | - return getDeclarativeConfigOrFallback( |
98 | | - openTelemetry, |
99 | | - propertyName, |
100 | | - (node, key) -> node.getString(key, defaultValue), |
101 | | - (key) -> getString(key, defaultValue)); |
| 93 | + return requireNonNull(getStringImpl(openTelemetry, defaultValue, propertyName)); |
| 94 | + } |
| 95 | + |
| 96 | + @Nullable |
| 97 | + public static String getStringImpl( |
| 98 | + OpenTelemetry openTelemetry, @Nullable String defaultValue, String... propertyName) { |
| 99 | + String result = |
| 100 | + getDeclarativeConfigOrFallback( |
| 101 | + openTelemetry, |
| 102 | + propertyName, |
| 103 | + (node, key) -> node.getString(key), |
| 104 | + (key) -> getString(key)); |
| 105 | + if (result == null) { |
| 106 | + return defaultValue; |
| 107 | + } |
| 108 | + return result; |
| 109 | + } |
| 110 | + |
| 111 | + @Nullable |
| 112 | + public static String getNullableString(OpenTelemetry openTelemetry, String... propertyName) { |
| 113 | + return getStringImpl(openTelemetry, null, propertyName); |
102 | 114 | } |
103 | 115 |
|
104 | 116 | private static List<String> getList(String propertyName, List<String> defaultValue) { |
|
0 commit comments