Don't require empty objects when referencing custom components (#6891)

This commit is contained in:
jack-berg 2024-11-18 15:55:00 -06:00 committed by GitHub
parent 2a97eaedc5
commit cde3d45f04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@ -166,6 +167,9 @@ public final class FileConfiguration {
Object model, ComponentLoader componentLoader) {
Map<String, Object> configurationMap =
MAPPER.convertValue(model, new TypeReference<Map<String, Object>>() {});
if (configurationMap == null) {
configurationMap = Collections.emptyMap();
}
return YamlStructuredConfigProperties.create(configurationMap, componentLoader);
}

View File

@ -130,4 +130,23 @@ class FileConfigurationCreateTest {
"Closing io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter");
logCapturer.assertContains("Closing io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor");
}
@Test
void parseAndCreate_EmptyComponentProviderConfig() {
String yaml =
"file_format: \"0.3\"\n"
+ "logger_provider:\n"
+ " processors:\n"
+ " - test:\n"
+ "tracer_provider:\n"
+ " processors:\n"
+ " - test:\n";
assertThatCode(
() ->
FileConfiguration.parseAndCreate(
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))))
.doesNotThrowAnyException();
;
}
}