Skip to content

Commit

Permalink
Don't require empty objects when referencing custom components (#6891)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Nov 18, 2024
1 parent 2a97eae commit cde3d45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -166,6 +167,9 @@ static StructuredConfigProperties toConfigProperties(
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,23 @@ void parseAndCreate_Exception_CleansUpPartials() {
"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();
;
}
}

0 comments on commit cde3d45

Please sign in to comment.