From 95ac98123df684050d28ce7f267bab1de6bbc354 Mon Sep 17 00:00:00 2001 From: Eunbin Son Date: Mon, 12 Oct 2026 09:55:39 +0900 Subject: [PATCH 1/2] Match environment variables for config keys containing underscores --- .../java/io/opentelemetry/common/impl/ConfigUtil.java | 11 +++++++---- .../io/opentelemetry/common/impl/ConfigUtilTest.java | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java b/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java index a129fd331bd..f7a4152399a 100644 --- a/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java +++ b/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java @@ -39,9 +39,10 @@ public static Properties safeSystemProperties() { * Return the system property or environment variable for the {@code key}. * *

Normalize the {@code key} using {@link #normalizePropertyKey(String)}. Match to system - * property keys also normalized with {@link #normalizePropertyKey(String)}. Match to environment - * variable keys normalized with {@link #normalizeEnvironmentVariableKey(String)}. System - * properties take priority over environment variables. + * property keys also normalized with {@link #normalizePropertyKey(String)}. Further normalize the + * {@code key} using {@link #normalizeEnvironmentVariableKey(String)} and match to environment + * variable keys normalized the same way. System properties take priority over environment + * variables. * * @param key the property key * @param defaultValue the fallback value if neither system property nor environment variable is @@ -61,8 +62,10 @@ public static String getString(String key, String defaultValue) { if (systemProperty != null) { return systemProperty; } + String environmentVariableKey = normalizeEnvironmentVariableKey(normalizedKey); return System.getenv().entrySet().stream() - .filter(entry -> normalizedKey.equals(normalizeEnvironmentVariableKey(entry.getKey()))) + .filter( + entry -> environmentVariableKey.equals(normalizeEnvironmentVariableKey(entry.getKey()))) .map(Map.Entry::getValue) .findFirst() .orElse(defaultValue); diff --git a/common/src/test/java/io/opentelemetry/common/impl/ConfigUtilTest.java b/common/src/test/java/io/opentelemetry/common/impl/ConfigUtilTest.java index 996376383af..de13d2bf69a 100644 --- a/common/src/test/java/io/opentelemetry/common/impl/ConfigUtilTest.java +++ b/common/src/test/java/io/opentelemetry/common/impl/ConfigUtilTest.java @@ -40,6 +40,7 @@ void getString_SystemPropertyNormalized() { @Test void getString_EnvironmentVariable() { assertThat(ConfigUtil.getString("config.key", "default")).isEqualTo("environment"); + assertThat(ConfigUtil.getString("config_key", "default")).isEqualTo("environment"); assertThat(ConfigUtil.getString("other.config.key", "default")).isEqualTo("default"); } From 52cb3536a47a7e021b4f05785ff22b4f3808d13e Mon Sep 17 00:00:00 2001 From: Eunbin Son Date: Tue, 13 Oct 2026 12:31:58 +0900 Subject: [PATCH 2/2] Add an environment variable example to ConfigUtil.getString Javadoc Show that a key with an underscore, such as otel.experimental.sdk.jvm_stacktrace, matches the environment variable OTEL_EXPERIMENTAL_SDK_JVM_STACKTRACE. Requested in review. Javadoc only, no behavior change. Generated-by: Claude Code --- .../src/main/java/io/opentelemetry/common/impl/ConfigUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java b/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java index f7a4152399a..cd8ee760793 100644 --- a/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java +++ b/common/src/main/java/io/opentelemetry/common/impl/ConfigUtil.java @@ -44,6 +44,9 @@ public static Properties safeSystemProperties() { * variable keys normalized the same way. System properties take priority over environment * variables. * + *

For example, {@code otel.experimental.sdk.jvm_stacktrace} matches the environment variable + * {@code OTEL_EXPERIMENTAL_SDK_JVM_STACKTRACE}. + * * @param key the property key * @param defaultValue the fallback value if neither system property nor environment variable is * set