diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java index 0bd9794fc14..2bac61f1436 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java @@ -232,6 +232,16 @@ public Map getMap(String name) { Map.Entry::getKey, Map.Entry::getValue, (first, next) -> next, LinkedHashMap::new)); } + @Nullable + @Override + public ExtendedConfigProperties getConfigProperties(String name) { + Map mapProperties = getMap(name); + if (mapProperties.isEmpty()) { + return null; + } + return DefaultConfigProperties.createFromMap(mapProperties); + } + /** * Return a new {@link DefaultConfigProperties} by overriding the {@code previousProperties} with * the {@code overrides}. diff --git a/sdk-extensions/autoconfigure-spi/src/test/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigPropertiesTest.java b/sdk-extensions/autoconfigure-spi/src/test/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigPropertiesTest.java index e0fe198dc9e..0c9ee5680ff 100644 --- a/sdk-extensions/autoconfigure-spi/src/test/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigPropertiesTest.java +++ b/sdk-extensions/autoconfigure-spi/src/test/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigPropertiesTest.java @@ -26,14 +26,24 @@ class ConfigPropertiesTest { void allValid() { Map properties = makeTestProps(); - ConfigProperties config = DefaultConfigProperties.createFromMap(properties); + DefaultConfigProperties config = DefaultConfigProperties.createFromMap(properties); assertThat(config.getString("test.string")).isEqualTo("str"); assertThat(config.getInt("test.int")).isEqualTo(10); assertThat(config.getLong("test.long")).isEqualTo(20); assertThat(config.getDouble("test.double")).isEqualTo(5.4); assertThat(config.getList("test.list")).containsExactly("cat", "dog", "bear"); assertThat(config.getMap("test.map")) - .containsExactly(entry("cat", "meow"), entry("dog", "bark"), entry("bear", "growl")); + .containsExactly( + entry("cat", "meow"), + entry("dog", "bark"), + entry("bear", "growl"), + entry("number", "1")); + ExtendedConfigProperties testMapConfig = config.getConfigProperties("test.map"); + assertThat(testMapConfig.getString("cat")).isEqualTo("meow"); + assertThat(testMapConfig.getString("dog")).isEqualTo("bark"); + assertThat(testMapConfig.getString("bear")).isEqualTo("growl"); + assertThat(testMapConfig.getString("number")).isEqualTo("1"); + assertThat(testMapConfig.getInt("number")).isEqualTo(1); assertThat(config.getDuration("test.duration")).isEqualTo(Duration.ofSeconds(1)); } @@ -48,19 +58,24 @@ void allValidUsingHyphens() { assertThat(config.getDouble("test-double")).isEqualTo(5.4); assertThat(config.getList("test-list")).containsExactly("cat", "dog", "bear"); assertThat(config.getMap("test-map")) - .containsExactly(entry("cat", "meow"), entry("dog", "bark"), entry("bear", "growl")); + .containsExactly( + entry("cat", "meow"), + entry("dog", "bark"), + entry("bear", "growl"), + entry("number", "1")); assertThat(config.getDuration("test-duration")).isEqualTo(Duration.ofSeconds(1)); } @Test void allMissing() { - ConfigProperties config = DefaultConfigProperties.createFromMap(emptyMap()); + DefaultConfigProperties config = DefaultConfigProperties.createFromMap(emptyMap()); assertThat(config.getString("test.string")).isNull(); assertThat(config.getInt("test.int")).isNull(); assertThat(config.getLong("test.long")).isNull(); assertThat(config.getDouble("test.double")).isNull(); assertThat(config.getList("test.list")).isEmpty(); assertThat(config.getMap("test.map")).isEmpty(); + assertThat(config.getConfigProperties("test.map")).isNull(); assertThat(config.getDuration("test.duration")).isNull(); } @@ -75,13 +90,14 @@ void allEmpty() { properties.put("test.map", ""); properties.put("test.duration", ""); - ConfigProperties config = DefaultConfigProperties.createFromMap(properties); + DefaultConfigProperties config = DefaultConfigProperties.createFromMap(properties); assertThat(config.getString("test.string")).isEmpty(); assertThat(config.getInt("test.int")).isNull(); assertThat(config.getLong("test.long")).isNull(); assertThat(config.getDouble("test.double")).isNull(); assertThat(config.getList("test.list")).isEmpty(); assertThat(config.getMap("test.map")).isEmpty(); + assertThat(config.getConfigProperties("test.map")).isNull(); assertThat(config.getDuration("test.duration")).isNull(); } @@ -275,7 +291,7 @@ private static Map makeTestProps() { properties.put("test.double", "5.4"); properties.put("test.boolean", "true"); properties.put("test.list", "cat,dog,bear"); - properties.put("test.map", "cat=meow,dog=bark,bear=growl,bird="); + properties.put("test.map", "cat=meow,dog=bark,bear=growl,bird=,number=1"); properties.put("test.duration", "1s"); return properties; }