diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java index fe1e310abc9..335c9a7c0ab 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java @@ -5,19 +5,29 @@ package io.opentelemetry.sdk.autoconfigure.spi.internal; +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import io.opentelemetry.sdk.metrics.export.MetricExporter; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; +import io.opentelemetry.sdk.trace.samplers.Sampler; /** * Provides configured instances of SDK extension components. {@link ComponentProvider} allows SDK * extension components which are not part of the core SDK to be referenced in file based * configuration. * + *

NOTE: when {@link #getType()} is {@link Resource}, the {@link #getName()} is not (currently) + * used, and {@link #create(StructuredConfigProperties)} is (currently) called with an empty {@link + * StructuredConfigProperties}. + * * @param the type of the SDK extension component. See {@link #getType()}. Supported values - * include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}. + * include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}, {@link + * SpanProcessor}, {@link LogRecordProcessor}, {@link TextMapPropagator}, {@link Sampler}, + * {@link Resource}. */ -// TODO: add support for Sampler, LogRecordProcessor, SpanProcessor, MetricReader public interface ComponentProvider { /** @@ -31,7 +41,8 @@ public interface ComponentProvider { * instances of a custom span exporter for the "acme" protocol, the name might be "acme". * *

This name MUST not be the same as any other component provider name which returns components - * of the same {@link #getType() type}. + * of the same {@link #getType() type}. In other words, {@link #getType()} and name form a + * composite key uniquely identifying the provider. */ String getName(); diff --git a/sdk-extensions/incubator/build.gradle.kts b/sdk-extensions/incubator/build.gradle.kts index 847a3b039e6..f562360655e 100644 --- a/sdk-extensions/incubator/build.gradle.kts +++ b/sdk-extensions/incubator/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { // io.opentelemetry.sdk.extension.incubator.fileconfig implementation("com.fasterxml.jackson.core:jackson-databind") + api("com.fasterxml.jackson.core:jackson-annotations") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") implementation(project(":sdk-extensions:autoconfigure")) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java index 1a28935086b..ec7fe6407ac 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java @@ -123,8 +123,7 @@ static Object loadYaml(InputStream inputStream, Map environmentV } /** - * Convert the {@code model} to a generic {@link StructuredConfigProperties}, which can be used to - * read configuration not part of the model. + * Convert the {@code model} to a generic {@link StructuredConfigProperties}. * * @param model the configuration model * @return a generic {@link StructuredConfigProperties} representation of the model @@ -133,6 +132,17 @@ public static StructuredConfigProperties toConfigProperties(OpenTelemetryConfigu return toConfigProperties((Object) model); } + /** + * Convert the {@code configuration} YAML to a generic {@link StructuredConfigProperties}. + * + * @param configuration configuration YAML + * @return a generic {@link StructuredConfigProperties} representation of the model + */ + public static StructuredConfigProperties toConfigProperties(InputStream configuration) { + Object yamlObj = loadYaml(configuration, System.getenv()); + return toConfigProperties(yamlObj); + } + static StructuredConfigProperties toConfigProperties(Object model) { Map configurationMap = MAPPER.convertValue(model, new TypeReference>() {}); diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigProperties.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigProperties.java index 2e9e20d3f0c..bc74b333cd4 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigProperties.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigProperties.java @@ -64,7 +64,7 @@ static YamlStructuredConfigProperties create(Map properties) { for (Map.Entry entry : properties.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); - if (isPrimitive(value)) { + if (isPrimitive(value) || value == null) { simpleEntries.put(key, value); continue; } @@ -283,7 +283,7 @@ public String toString() { } /** Return a map representation of the data. */ - Map toMap() { + public Map toMap() { Map result = new HashMap<>(simpleEntries); listEntries.forEach( (key, value) -> diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigPropertiesTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigPropertiesTest.java index 5c4f3d71333..b29e4c97162 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigPropertiesTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigPropertiesTest.java @@ -33,6 +33,7 @@ class YamlStructuredConfigPropertiesTest { + " int_key: 1\n" + " float_key: 1.1\n" + " bool_key: true\n" + + " null_key:\n" + " str_list_key: [val1, val2]\n" + " int_list_key: [1, 2]\n" + " float_list_key: [1.1, 2.2]\n" @@ -90,6 +91,7 @@ void additionalProperties() { "int_key", "float_key", "bool_key", + "null_key", "str_list_key", "int_list_key", "float_list_key", @@ -101,7 +103,10 @@ void additionalProperties() { assertThat(otherProps.getInt("int_key")).isEqualTo(1); assertThat(otherProps.getLong("int_key")).isEqualTo(1); assertThat(otherProps.getDouble("float_key")).isEqualTo(1.1); - assertThat(otherProps.getBoolean("bool_key")).isTrue(); + assertThat(otherProps.getString("null_key")).isNull(); + assertThat(otherProps.getInt("null_key")).isNull(); + assertThat(otherProps.getLong("null_key")).isNull(); + assertThat(otherProps.getBoolean("null_key")).isNull(); assertThat(otherProps.getScalarList("str_list_key", String.class)) .isEqualTo(Arrays.asList("val1", "val2")); assertThat(otherProps.getScalarList("int_list_key", Long.class))