diff --git a/api/incubator/build.gradle.kts b/api/incubator/build.gradle.kts index bdf12950acf..205b5504a0f 100644 --- a/api/incubator/build.gradle.kts +++ b/api/incubator/build.gradle.kts @@ -14,6 +14,9 @@ dependencies { annotationProcessor("com.google.auto.value:auto-value") + // To use parsed config file as input for InstrumentationConfigUtilTest + testImplementation(project(":sdk-extensions:incubator")) + testImplementation(project(":sdk:testing")) testImplementation(project(":api:testing-internal")) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ConfigProvider.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ConfigProvider.java new file mode 100644 index 00000000000..62cc044e653 --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ConfigProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +import javax.annotation.Nullable; +import javax.annotation.concurrent.ThreadSafe; + +/** + * A registry for accessing declarative configuration. + * + *

The name Provider is for consistency with other languages and it is NOT loaded + * using reflection. + * + *

See {@link InstrumentationConfigUtil} for convenience methods for extracting config from + * {@link ConfigProvider}. + */ +@ThreadSafe +public interface ConfigProvider { + + /** + * Returns the {@link DeclarativeConfigProperties} corresponding to instrumentation + * config, or {@code null} if unavailable. + * + * @return the instrumentation {@link DeclarativeConfigProperties} + */ + @Nullable + DeclarativeConfigProperties getInstrumentationConfig(); + + /** Returns a no-op {@link ConfigProvider}. */ + static ConfigProvider noop() { + return () -> null; + } +} diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigException.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigException.java new file mode 100644 index 00000000000..3ce49c6454d --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigException.java @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +/** An exception that is thrown when errors occur with declarative configuration. */ +public final class DeclarativeConfigException extends RuntimeException { + + private static final long serialVersionUID = 3036584181551130522L; + + /** Create a new configuration exception with specified {@code message} and without a cause. */ + public DeclarativeConfigException(String message) { + super(message); + } + + /** Create a new configuration exception with specified {@code message} and {@code cause}. */ + public DeclarativeConfigException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/StructuredConfigProperties.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java similarity index 68% rename from sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/StructuredConfigProperties.java rename to api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java index 99eff27f00b..114d3bbe440 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/StructuredConfigProperties.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java @@ -3,43 +3,41 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.autoconfigure.spi.internal; +package io.opentelemetry.api.incubator.config; import static io.opentelemetry.api.internal.ConfigUtil.defaultIfNull; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import java.util.List; import java.util.Set; import javax.annotation.Nullable; /** - * An interface for accessing structured configuration data. + * An interface for accessing declarative configuration data. * - *

An instance of {@link StructuredConfigProperties} is equivalent to a An instance of {@link DeclarativeConfigProperties} is equivalent to a YAML mapping node. It has accessors for * reading scalar properties, {@link #getStructured(String)} for reading children which are * themselves mappings, and {@link #getStructuredList(String)} for reading children which are * sequences of mappings. */ -public interface StructuredConfigProperties { +public interface DeclarativeConfigProperties { /** - * Return an empty {@link StructuredConfigProperties} instance. + * Return an empty {@link DeclarativeConfigProperties} instance. * *

Useful for walking the tree without checking for null. For example, to access a string key * nested at .foo.bar.baz, call: {@code config.getStructured("foo", empty()).getStructured("bar", * empty()).getString("baz")}. */ - static StructuredConfigProperties empty() { - return EmptyStructuredConfigProperties.getInstance(); + static DeclarativeConfigProperties empty() { + return EmptyDeclarativeConfigProperties.getInstance(); } /** * Returns a {@link String} configuration property. * * @return null if the property has not been configured - * @throws ConfigurationException if the property is not a valid scalar string + * @throws DeclarativeConfigException if the property is not a valid scalar string */ @Nullable String getString(String name); @@ -49,7 +47,7 @@ static StructuredConfigProperties empty() { * * @return a {@link String} configuration property or {@code defaultValue} if a property with * {@code name} has not been configured - * @throws ConfigurationException if the property is not a valid scalar string + * @throws DeclarativeConfigException if the property is not a valid scalar string */ default String getString(String name, String defaultValue) { return defaultIfNull(getString(name), defaultValue); @@ -60,7 +58,7 @@ default String getString(String name, String defaultValue) { * {@link Boolean#parseBoolean(String)} for handling the values. * * @return null if the property has not been configured - * @throws ConfigurationException if the property is not a valid scalar boolean + * @throws DeclarativeConfigException if the property is not a valid scalar boolean */ @Nullable Boolean getBoolean(String name); @@ -70,7 +68,7 @@ default String getString(String name, String defaultValue) { * * @return a {@link Boolean} configuration property or {@code defaultValue} if a property with * {@code name} has not been configured - * @throws ConfigurationException if the property is not a valid scalar boolean + * @throws DeclarativeConfigException if the property is not a valid scalar boolean */ default boolean getBoolean(String name, boolean defaultValue) { return defaultIfNull(getBoolean(name), defaultValue); @@ -83,7 +81,7 @@ default boolean getBoolean(String name, boolean defaultValue) { * {@link Long#intValue()} which may result in loss of precision. * * @return null if the property has not been configured - * @throws ConfigurationException if the property is not a valid scalar integer + * @throws DeclarativeConfigException if the property is not a valid scalar integer */ @Nullable Integer getInt(String name); @@ -96,7 +94,7 @@ default boolean getBoolean(String name, boolean defaultValue) { * * @return a {@link Integer} configuration property or {@code defaultValue} if a property with * {@code name} has not been configured - * @throws ConfigurationException if the property is not a valid scalar integer + * @throws DeclarativeConfigException if the property is not a valid scalar integer */ default int getInt(String name, int defaultValue) { return defaultIfNull(getInt(name), defaultValue); @@ -106,7 +104,7 @@ default int getInt(String name, int defaultValue) { * Returns a {@link Long} configuration property. * * @return null if the property has not been configured - * @throws ConfigurationException if the property is not a valid scalar long + * @throws DeclarativeConfigException if the property is not a valid scalar long */ @Nullable Long getLong(String name); @@ -116,7 +114,7 @@ default int getInt(String name, int defaultValue) { * * @return a {@link Long} configuration property or {@code defaultValue} if a property with {@code * name} has not been configured - * @throws ConfigurationException if the property is not a valid scalar long + * @throws DeclarativeConfigException if the property is not a valid scalar long */ default long getLong(String name, long defaultValue) { return defaultIfNull(getLong(name), defaultValue); @@ -126,7 +124,7 @@ default long getLong(String name, long defaultValue) { * Returns a {@link Double} configuration property. * * @return null if the property has not been configured - * @throws ConfigurationException if the property is not a valid scalar double + * @throws DeclarativeConfigException if the property is not a valid scalar double */ @Nullable Double getDouble(String name); @@ -136,7 +134,7 @@ default long getLong(String name, long defaultValue) { * * @return a {@link Double} configuration property or {@code defaultValue} if a property with * {@code name} has not been configured - * @throws ConfigurationException if the property is not a valid scalar double + * @throws DeclarativeConfigException if the property is not a valid scalar double */ default double getDouble(String name, double defaultValue) { return defaultIfNull(getDouble(name), defaultValue); @@ -150,8 +148,8 @@ default double getDouble(String name, double defaultValue) { * @param scalarType the scalar type, one of {@link String}, {@link Boolean}, {@link Long} or * {@link Double} * @return a {@link List} configuration property, or null if the property has not been configured - * @throws ConfigurationException if the property is not a valid sequence of scalars, or if {@code - * scalarType} is not supported + * @throws DeclarativeConfigException if the property is not a valid sequence of scalars, or if + * {@code scalarType} is not supported */ @Nullable List getScalarList(String name, Class scalarType); @@ -160,56 +158,58 @@ default double getDouble(String name, double defaultValue) { * Returns a {@link List} configuration property. Entries which are not strings are converted to * their string representation. * - * @see ConfigProperties#getList(String name) + * @param name the property name + * @param scalarType the scalar type, one of {@link String}, {@link Boolean}, {@link Long} or + * {@link Double} * @return a {@link List} configuration property or {@code defaultValue} if a property with {@code * name} has not been configured - * @throws ConfigurationException if the property is not a valid sequence of scalars + * @throws DeclarativeConfigException if the property is not a valid sequence of scalars */ default List getScalarList(String name, Class scalarType, List defaultValue) { return defaultIfNull(getScalarList(name, scalarType), defaultValue); } /** - * Returns a {@link StructuredConfigProperties} configuration property. + * Returns a {@link DeclarativeConfigProperties} configuration property. * * @return a map-valued configuration property, or {@code null} if {@code name} has not been * configured - * @throws ConfigurationException if the property is not a mapping + * @throws DeclarativeConfigException if the property is not a mapping */ @Nullable - StructuredConfigProperties getStructured(String name); + DeclarativeConfigProperties getStructured(String name); /** - * Returns a {@link StructuredConfigProperties} configuration property. + * Returns a list of {@link DeclarativeConfigProperties} configuration property. * * @return a map-valued configuration property, or {@code defaultValue} if {@code name} has not * been configured - * @throws ConfigurationException if the property is not a mapping + * @throws DeclarativeConfigException if the property is not a mapping */ - default StructuredConfigProperties getStructured( - String name, StructuredConfigProperties defaultValue) { + default DeclarativeConfigProperties getStructured( + String name, DeclarativeConfigProperties defaultValue) { return defaultIfNull(getStructured(name), defaultValue); } /** - * Returns a list of {@link StructuredConfigProperties} configuration property. + * Returns a list of {@link DeclarativeConfigProperties} configuration property. * * @return a list of map-valued configuration property, or {@code null} if {@code name} has not * been configured - * @throws ConfigurationException if the property is not a sequence of mappings + * @throws DeclarativeConfigException if the property is not a sequence of mappings */ @Nullable - List getStructuredList(String name); + List getStructuredList(String name); /** - * Returns a list of {@link StructuredConfigProperties} configuration property. + * Returns a list of {@link DeclarativeConfigProperties} configuration property. * * @return a list of map-valued configuration property, or {@code defaultValue} if {@code name} * has not been configured - * @throws ConfigurationException if the property is not a sequence of mappings + * @throws DeclarativeConfigException if the property is not a sequence of mappings */ - default List getStructuredList( - String name, List defaultValue) { + default List getStructuredList( + String name, List defaultValue) { return defaultIfNull(getStructuredList(name), defaultValue); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/EmptyStructuredConfigProperties.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyDeclarativeConfigProperties.java similarity index 63% rename from sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/EmptyStructuredConfigProperties.java rename to api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyDeclarativeConfigProperties.java index 2315dfa013f..77b8a265492 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/EmptyStructuredConfigProperties.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyDeclarativeConfigProperties.java @@ -3,22 +3,22 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.autoconfigure.spi.internal; +package io.opentelemetry.api.incubator.config; import java.util.Collections; import java.util.List; import java.util.Set; import javax.annotation.Nullable; -/** Empty instance of {@link StructuredConfigProperties}. */ -final class EmptyStructuredConfigProperties implements StructuredConfigProperties { +/** Empty instance of {@link DeclarativeConfigProperties}. */ +final class EmptyDeclarativeConfigProperties implements DeclarativeConfigProperties { - private static final EmptyStructuredConfigProperties INSTANCE = - new EmptyStructuredConfigProperties(); + private static final EmptyDeclarativeConfigProperties INSTANCE = + new EmptyDeclarativeConfigProperties(); - private EmptyStructuredConfigProperties() {} + private EmptyDeclarativeConfigProperties() {} - static EmptyStructuredConfigProperties getInstance() { + static EmptyDeclarativeConfigProperties getInstance() { return INSTANCE; } @@ -60,13 +60,13 @@ public List getScalarList(String name, Class scalarType) { @Nullable @Override - public StructuredConfigProperties getStructured(String name) { + public DeclarativeConfigProperties getStructured(String name) { return null; } @Nullable @Override - public List getStructuredList(String name) { + public List getStructuredList(String name) { return null; } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/GlobalConfigProvider.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/GlobalConfigProvider.java new file mode 100644 index 00000000000..b0daef4968d --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/GlobalConfigProvider.java @@ -0,0 +1,63 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.Nullable; + +/** + * This class provides a temporary global accessor for {@link ConfigProvider} until the + * instrumentation config API is marked stable. It will eventually be merged into {@link + * GlobalOpenTelemetry}. + */ +// We intentionally assign to be used for error reporting. +@SuppressWarnings("StaticAssignmentOfThrowable") +public final class GlobalConfigProvider { + + private static final AtomicReference instance = + new AtomicReference<>(ConfigProvider.noop()); + + @SuppressWarnings("NonFinalStaticField") + @Nullable + private static volatile Throwable setInstanceCaller; + + private GlobalConfigProvider() {} + + /** Returns the globally registered {@link ConfigProvider}. */ + // instance cannot be set to null + @SuppressWarnings("NullAway") + public static ConfigProvider get() { + return instance.get(); + } + + /** + * Sets the global {@link ConfigProvider}. Future calls to {@link #get()} will return the provided + * {@link ConfigProvider} instance. This should be called once as early as possible in your + * application initialization logic. + * + * @throws IllegalStateException when called more than once + */ + public static void set(ConfigProvider configProvider) { + boolean changed = instance.compareAndSet(ConfigProvider.noop(), configProvider); + if (!changed && (configProvider != ConfigProvider.noop())) { + throw new IllegalStateException( + "GlobalConfigProvider.set has already been called. GlobalConfigProvider.set " + + "must be called only once before any calls to GlobalConfigProvider.get. " + + "Previous invocation set to cause of this exception.", + setInstanceCaller); + } + setInstanceCaller = new Throwable(); + } + + /** + * Unsets the global {@link ConfigProvider}. This is only meant to be used from tests which need + * to reconfigure {@link ConfigProvider}. + */ + public static void resetForTest() { + instance.set(ConfigProvider.noop()); + } +} diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/InstrumentationConfigUtil.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/InstrumentationConfigUtil.java new file mode 100644 index 00000000000..da611b780b4 --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/InstrumentationConfigUtil.java @@ -0,0 +1,143 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import javax.annotation.Nullable; + +/** + * A collection of convenience methods to extract instrumentation config from {@link + * ConfigProvider#getInstrumentationConfig()}. + */ +public class InstrumentationConfigUtil { + + /** + * Return a map representation of the peer service map entries in {@code + * .instrumentation.general.peer.service_mapping}, or null if none is configured. + * + * @throws DeclarativeConfigException if an unexpected type is encountered accessing the property + */ + @Nullable + public static Map peerServiceMapping(ConfigProvider configProvider) { + List serviceMappingList = + getOrNull( + configProvider, + config -> config.getStructuredList("service_mapping"), + "general", + "peer"); + if (serviceMappingList == null) { + return null; + } + Map serviceMapping = new LinkedHashMap<>(); + serviceMappingList.forEach( + entry -> { + String peer = entry.getString("peer"); + String service = entry.getString("service"); + if (peer != null && service != null) { + serviceMapping.put(peer, service); + } + }); + return serviceMapping.isEmpty() ? null : serviceMapping; + } + + /** + * Return {@code .instrumentation.general.http.client.request_captured_headers}, or null if none + * is configured. + * + * @throws DeclarativeConfigException if an unexpected type is encountered accessing the property + */ + @Nullable + public static List httpClientRequestCapturedHeaders(ConfigProvider configProvider) { + return getOrNull( + configProvider, + config -> config.getScalarList("request_captured_headers", String.class), + "general", + "http", + "client"); + } + + /** + * Return {@code .instrumentation.general.http.client.response_captured_headers}, or null if none + * is configured. + * + * @throws DeclarativeConfigException if an unexpected type is encountered accessing the property + */ + @Nullable + public static List httpClientResponseCapturedHeaders(ConfigProvider configProvider) { + return getOrNull( + configProvider, + config -> config.getScalarList("response_captured_headers", String.class), + "general", + "http", + "client"); + } + + /** + * Return {@code .instrumentation.general.http.server.request_captured_headers}, or null if none + * is configured. + * + * @throws DeclarativeConfigException if an unexpected type is encountered accessing the property + */ + @Nullable + public static List httpServerRequestCapturedHeaders(ConfigProvider configProvider) { + return getOrNull( + configProvider, + config -> config.getScalarList("request_captured_headers", String.class), + "general", + "http", + "server"); + } + + /** + * Return {@code .instrumentation.general.http.server.response_captured_headers}, or null if none + * is configured. + * + * @throws DeclarativeConfigException if an unexpected type is encountered accessing the property + */ + @Nullable + public static List httpSeverResponseCapturedHeaders(ConfigProvider configProvider) { + return getOrNull( + configProvider, + config -> config.getScalarList("response_captured_headers", String.class), + "general", + "http", + "server"); + } + + /** + * Return {@code .instrumentation.java.}, or null if none is configured. + * + * @throws DeclarativeConfigException if an unexpected type is encountered accessing the property + */ + @Nullable + public static DeclarativeConfigProperties javaInstrumentationConfig( + ConfigProvider configProvider, String instrumentationName) { + return getOrNull(configProvider, config -> config.getStructured(instrumentationName), "java"); + } + + @Nullable + private static T getOrNull( + ConfigProvider configProvider, + Function accessor, + String... segments) { + DeclarativeConfigProperties config = configProvider.getInstrumentationConfig(); + if (config == null) { + return null; + } + for (String segment : segments) { + config = config.getStructured(segment); + if (config == null) { + return null; + } + } + return accessor.apply(config); + } + + private InstrumentationConfigUtil() {} +} diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/ConfigProviderTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/ConfigProviderTest.java new file mode 100644 index 00000000000..9c9e4bf41e1 --- /dev/null +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/ConfigProviderTest.java @@ -0,0 +1,20 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.api.incubator.config.ConfigProvider; +import org.junit.jupiter.api.Test; + +class ConfigProviderTest { + + @Test + void noopEquality() { + ConfigProvider noop = ConfigProvider.noop(); + assertThat(ConfigProvider.noop()).isSameAs(noop); + } +} diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/config/GlobalConfigProviderTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/config/GlobalConfigProviderTest.java new file mode 100644 index 00000000000..ecd837a5298 --- /dev/null +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/config/GlobalConfigProviderTest.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class GlobalConfigProviderTest { + + @BeforeAll + static void beforeClass() { + GlobalConfigProvider.resetForTest(); + } + + @AfterEach + void after() { + GlobalConfigProvider.resetForTest(); + } + + @Test + void setAndGet() { + assertThat(GlobalConfigProvider.get()).isEqualTo(ConfigProvider.noop()); + ConfigProvider configProvider = DeclarativeConfigProperties::empty; + GlobalConfigProvider.set(configProvider); + assertThat(GlobalConfigProvider.get()).isSameAs(configProvider); + } + + @Test + void setThenSet() { + ConfigProvider configProvider = DeclarativeConfigProperties::empty; + GlobalConfigProvider.set(configProvider); + assertThatThrownBy(() -> GlobalConfigProvider.set(configProvider)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("GlobalConfigProvider.set has already been called") + .hasStackTraceContaining("setThenSet"); + } +} diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/config/InstrumentationConfigUtilTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/config/InstrumentationConfigUtilTest.java new file mode 100644 index 00000000000..94da0f2d10b --- /dev/null +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/config/InstrumentationConfigUtilTest.java @@ -0,0 +1,169 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.ImmutableMap; +import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration; +import io.opentelemetry.sdk.extension.incubator.fileconfig.SdkConfigProvider; +import io.opentelemetry.sdk.extension.incubator.fileconfig.YamlDeclarativeConfigProperties; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import org.junit.jupiter.api.Test; + +class InstrumentationConfigUtilTest { + + /** + * See kitchen-sink.yaml. + */ + private static final String kitchenSinkInstrumentationConfig = + "instrumentation:\n" + + " general:\n" + + " peer:\n" + + " service_mapping:\n" + + " - peer: 1.2.3.4\n" + + " service: FooService\n" + + " - peer: 2.3.4.5\n" + + " service: BarService\n" + + " http:\n" + + " client:\n" + + " request_captured_headers:\n" + + " - client-request-header1\n" + + " - client-request-header2\n" + + " response_captured_headers:\n" + + " - client-response-header1\n" + + " - client-response-header2\n" + + " server:\n" + + " request_captured_headers:\n" + + " - server-request-header1\n" + + " - server-request-header2\n" + + " response_captured_headers:\n" + + " - server-response-header1\n" + + " - server-response-header2\n" + + " java:\n" + + " example:\n" + + " property: \"value\""; + + private static final ConfigProvider kitchenSinkConfigProvider = + toConfigProvider(kitchenSinkInstrumentationConfig); + private static final ConfigProvider emptyInstrumentationConfigProvider = + toConfigProvider("instrumentation:\n"); + private static final ConfigProvider emptyGeneralConfigProvider = + toConfigProvider("instrumentation:\n general:\n"); + private static final ConfigProvider emptyHttpConfigProvider = + toConfigProvider("instrumentation:\n general:\n http:\n"); + + private static ConfigProvider toConfigProvider(String configYaml) { + OpenTelemetryConfigurationModel configuration = + DeclarativeConfiguration.parse( + new ByteArrayInputStream(configYaml.getBytes(StandardCharsets.UTF_8))); + return SdkConfigProvider.create(configuration); + } + + @Test + void peerServiceMapping() { + assertThat(InstrumentationConfigUtil.peerServiceMapping(kitchenSinkConfigProvider)) + .isEqualTo(ImmutableMap.of("1.2.3.4", "FooService", "2.3.4.5", "BarService")); + assertThat(InstrumentationConfigUtil.peerServiceMapping(emptyInstrumentationConfigProvider)) + .isNull(); + assertThat(InstrumentationConfigUtil.peerServiceMapping(emptyGeneralConfigProvider)).isNull(); + assertThat(InstrumentationConfigUtil.peerServiceMapping(emptyHttpConfigProvider)).isNull(); + } + + @Test + void httpClientRequestCapturedHeaders() { + assertThat( + InstrumentationConfigUtil.httpClientRequestCapturedHeaders(kitchenSinkConfigProvider)) + .isEqualTo(Arrays.asList("client-request-header1", "client-request-header2")); + assertThat( + InstrumentationConfigUtil.httpClientRequestCapturedHeaders( + emptyInstrumentationConfigProvider)) + .isNull(); + assertThat( + InstrumentationConfigUtil.httpClientRequestCapturedHeaders(emptyGeneralConfigProvider)) + .isNull(); + assertThat(InstrumentationConfigUtil.httpClientRequestCapturedHeaders(emptyHttpConfigProvider)) + .isNull(); + } + + @Test + void httpClientResponseCapturedHeaders() { + assertThat( + InstrumentationConfigUtil.httpClientResponseCapturedHeaders(kitchenSinkConfigProvider)) + .isEqualTo(Arrays.asList("client-response-header1", "client-response-header2")); + assertThat( + InstrumentationConfigUtil.httpClientResponseCapturedHeaders( + emptyInstrumentationConfigProvider)) + .isNull(); + assertThat( + InstrumentationConfigUtil.httpClientResponseCapturedHeaders(emptyGeneralConfigProvider)) + .isNull(); + assertThat(InstrumentationConfigUtil.httpClientResponseCapturedHeaders(emptyHttpConfigProvider)) + .isNull(); + } + + @Test + void httpServerRequestCapturedHeaders() { + assertThat( + InstrumentationConfigUtil.httpServerRequestCapturedHeaders(kitchenSinkConfigProvider)) + .isEqualTo(Arrays.asList("server-request-header1", "server-request-header2")); + assertThat( + InstrumentationConfigUtil.httpServerRequestCapturedHeaders( + emptyInstrumentationConfigProvider)) + .isNull(); + assertThat( + InstrumentationConfigUtil.httpServerRequestCapturedHeaders(emptyGeneralConfigProvider)) + .isNull(); + assertThat(InstrumentationConfigUtil.httpServerRequestCapturedHeaders(emptyHttpConfigProvider)) + .isNull(); + } + + @Test + void httpServerResponseCapturedHeaders() { + assertThat( + InstrumentationConfigUtil.httpSeverResponseCapturedHeaders(kitchenSinkConfigProvider)) + .isEqualTo(Arrays.asList("server-response-header1", "server-response-header2")); + assertThat( + InstrumentationConfigUtil.httpSeverResponseCapturedHeaders( + emptyInstrumentationConfigProvider)) + .isNull(); + assertThat( + InstrumentationConfigUtil.httpSeverResponseCapturedHeaders(emptyGeneralConfigProvider)) + .isNull(); + assertThat(InstrumentationConfigUtil.httpSeverResponseCapturedHeaders(emptyHttpConfigProvider)) + .isNull(); + } + + @Test + void javaInstrumentationConfig() { + assertThat( + InstrumentationConfigUtil.javaInstrumentationConfig( + kitchenSinkConfigProvider, "example")) + .isNotNull() + .isInstanceOfSatisfying( + YamlDeclarativeConfigProperties.class, + exampleConfig -> + assertThat(exampleConfig.toMap()).isEqualTo(ImmutableMap.of("property", "value"))); + assertThat( + InstrumentationConfigUtil.javaInstrumentationConfig(kitchenSinkConfigProvider, "foo")) + .isNull(); + assertThat( + InstrumentationConfigUtil.javaInstrumentationConfig( + emptyInstrumentationConfigProvider, "example")) + .isNull(); + assertThat( + InstrumentationConfigUtil.javaInstrumentationConfig( + emptyGeneralConfigProvider, "example")) + .isNull(); + assertThat( + InstrumentationConfigUtil.javaInstrumentationConfig(emptyHttpConfigProvider, "example")) + .isNull(); + } +} diff --git a/exporters/common/build.gradle.kts b/exporters/common/build.gradle.kts index f311510f83d..ef16c7d7c39 100644 --- a/exporters/common/build.gradle.kts +++ b/exporters/common/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { api(project(":api:all")) api(project(":sdk-extensions:autoconfigure-spi")) + compileOnly(project(":api:incubator")) compileOnly(project(":sdk:common")) compileOnly(project(":exporters:common:compile-stub")) diff --git a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/ExporterBuilderUtil.java b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/ExporterBuilderUtil.java index 81caace0178..e493f5d72cb 100644 --- a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/ExporterBuilderUtil.java +++ b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/ExporterBuilderUtil.java @@ -7,9 +7,9 @@ import static io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.metrics.Aggregation; import io.opentelemetry.sdk.metrics.InstrumentType; @@ -63,7 +63,7 @@ public static void configureExporterMemoryMode( /** Invoke the {@code memoryModeConsumer} with the configured {@link MemoryMode}. */ public static void configureExporterMemoryMode( - StructuredConfigProperties config, Consumer memoryModeConsumer) { + DeclarativeConfigProperties config, Consumer memoryModeConsumer) { String memoryModeStr = config.getString("memory_mode"); if (memoryModeStr == null) { return; diff --git a/exporters/logging-otlp/build.gradle.kts b/exporters/logging-otlp/build.gradle.kts index a65f52f8522..0870f2c9937 100644 --- a/exporters/logging-otlp/build.gradle.kts +++ b/exporters/logging-otlp/build.gradle.kts @@ -14,10 +14,12 @@ dependencies { implementation(project(":sdk:logs")) implementation(project(":exporters:otlp:common")) + compileOnly(project(":api:incubator")) implementation(project(":sdk-extensions:autoconfigure-spi")) implementation("com.fasterxml.jackson.core:jackson-core") + testImplementation(project(":api:incubator")) testImplementation(project(":sdk:testing")) testImplementation("com.google.guava:guava") diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java index 204f5673c08..9faec97e778 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java @@ -5,8 +5,8 @@ package io.opentelemetry.exporter.logging.otlp.internal.logs; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.logs.export.LogRecordExporter; /** @@ -29,7 +29,7 @@ public String getName() { } @Override - public LogRecordExporter create(StructuredConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config) { OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder(); return builder.build(); } diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java index f98b81b69af..bf8f70862cc 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java @@ -12,12 +12,12 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; import io.github.netmikey.logunit.api.LogCapturer; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.otlp.internal.logs.OtlpStdoutLogRecordExporter; import io.opentelemetry.exporter.logging.otlp.internal.logs.OtlpStdoutLogRecordExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import java.io.BufferedOutputStream; @@ -205,7 +205,7 @@ void defaultToString() { } private OtlpStdoutLogRecordExporter exporterFromComponentProvider( - StructuredConfigProperties properties) { + DeclarativeConfigProperties properties) { return (OtlpStdoutLogRecordExporter) ((ComponentProvider) loadSpi(ComponentProvider.class) @@ -222,7 +222,7 @@ private OtlpStdoutLogRecordExporter exporterFromComponentProvider( @Test void componentProviderConfig() { - StructuredConfigProperties properties = mock(StructuredConfigProperties.class); + DeclarativeConfigProperties properties = mock(DeclarativeConfigProperties.class); OtlpStdoutLogRecordExporter exporter = exporterFromComponentProvider(properties); assertThat(exporter).extracting("wrapperJsonObject").isEqualTo(true); diff --git a/exporters/logging/build.gradle.kts b/exporters/logging/build.gradle.kts index 6feefb00fe8..82e96771834 100644 --- a/exporters/logging/build.gradle.kts +++ b/exporters/logging/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { api(project(":sdk:all")) implementation(project(":sdk-extensions:autoconfigure-spi")) + compileOnly(project(":api:incubator")) testImplementation(project(":sdk:testing")) } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java index 4d03480b335..e220219325a 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.exporter.logging.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.logs.export.LogRecordExporter; /** @@ -30,7 +30,7 @@ public String getName() { } @Override - public LogRecordExporter create(StructuredConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config) { return SystemOutLogRecordExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java index 48a449ff0f0..09ada70eb0c 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.exporter.logging.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.LoggingMetricExporter; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.metrics.export.MetricExporter; /** @@ -30,7 +30,7 @@ public String getName() { } @Override - public MetricExporter create(StructuredConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config) { return LoggingMetricExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java index c212a77d5d4..06c6d4f09fb 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.exporter.logging.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.trace.export.SpanExporter; /** @@ -29,7 +29,7 @@ public String getName() { } @Override - public SpanExporter create(StructuredConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config) { return LoggingSpanExporter.create(); } } diff --git a/exporters/otlp/all/build.gradle.kts b/exporters/otlp/all/build.gradle.kts index 0c0ef6b75b7..841521cb8ca 100644 --- a/exporters/otlp/all/build.gradle.kts +++ b/exporters/otlp/all/build.gradle.kts @@ -19,6 +19,7 @@ dependencies { implementation(project(":exporters:otlp:common")) implementation(project(":exporters:sender:okhttp")) implementation(project(":sdk-extensions:autoconfigure-spi")) + compileOnly(project(":api:incubator")) compileOnly("io.grpc:grpc-stub") diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java index 1ca885bf5a0..21dd2b601ae 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java @@ -7,11 +7,11 @@ import static io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.internal.ExporterBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.common.export.RetryPolicy; import io.opentelemetry.sdk.metrics.Aggregation; @@ -59,7 +59,7 @@ public static String getOtlpProtocol(String dataType, ConfigProperties config) { } /** Determine the configured OTLP protocol for the {@code dataType}. */ - public static String getStructuredConfigOtlpProtocol(StructuredConfigProperties config) { + public static String getStructuredConfigOtlpProtocol(DeclarativeConfigProperties config) { return config.getString("protocol", PROTOCOL_GRPC); } @@ -167,7 +167,7 @@ public static void configureOtlpExporterBuilder( @SuppressWarnings("TooManyParameters") public static void configureOtlpExporterBuilder( String dataType, - StructuredConfigProperties config, + DeclarativeConfigProperties config, Consumer setEndpoint, BiConsumer addHeader, Consumer setCompression, @@ -191,7 +191,7 @@ public static void configureOtlpExporterBuilder( configureOtlpHeaders(headersListConfig, dataType, addHeader); } - List headers = config.getStructuredList("headers"); + List headers = config.getStructuredList("headers"); if (headers != null) { headers.forEach( header -> { @@ -285,7 +285,7 @@ public static void configureOtlpAggregationTemporality( } public static void configureOtlpAggregationTemporality( - StructuredConfigProperties config, + DeclarativeConfigProperties config, Consumer aggregationTemporalitySelectorConsumer) { String temporalityStr = config.getString("temporality_preference"); if (temporalityStr == null) { @@ -328,7 +328,7 @@ public static void configureOtlpHistogramDefaultAggregation( * DefaultAggregationSelector}. */ public static void configureOtlpHistogramDefaultAggregation( - StructuredConfigProperties config, + DeclarativeConfigProperties config, Consumer defaultAggregationSelectorConsumer) { String defaultHistogramAggregation = config.getString("default_histogram_aggregation"); if (defaultHistogramAggregation == null) { diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterComponentProvider.java index cd7d97a1d46..5e3492674d2 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterComponentProvider.java @@ -9,13 +9,13 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC; import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.logs.export.LogRecordExporter; /** @@ -39,7 +39,7 @@ public String getName() { } @Override - public LogRecordExporter create(StructuredConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config) { String protocol = OtlpConfigUtil.getStructuredConfigOtlpProtocol(config); if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterComponentProvider.java index bac3b205835..fe1cf3e86cc 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterComponentProvider.java @@ -9,13 +9,13 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC; import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.metrics.export.MetricExporter; /** @@ -38,7 +38,7 @@ public String getName() { } @Override - public MetricExporter create(StructuredConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config) { String protocol = OtlpConfigUtil.getStructuredConfigOtlpProtocol(config); if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterComponentProvider.java index 707ff0c4383..7494abf3588 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterComponentProvider.java @@ -9,13 +9,13 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC; import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.trace.export.SpanExporter; /** @@ -38,7 +38,7 @@ public String getName() { } @Override - public SpanExporter create(StructuredConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config) { String protocol = OtlpConfigUtil.getStructuredConfigOtlpProtocol(config); if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { diff --git a/exporters/prometheus/build.gradle.kts b/exporters/prometheus/build.gradle.kts index 8fe244b3f3d..98a67d731bb 100644 --- a/exporters/prometheus/build.gradle.kts +++ b/exporters/prometheus/build.gradle.kts @@ -9,6 +9,7 @@ otelJava.moduleName.set("io.opentelemetry.exporter.prometheus") dependencies { api(project(":sdk:metrics")) + compileOnly(project(":api:incubator")) implementation(project(":exporters:common")) implementation(project(":sdk-extensions:autoconfigure-spi")) implementation("io.prometheus:prometheus-metrics-exporter-httpserver") diff --git a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java index dc57d2bcbe3..bcba3022693 100644 --- a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java +++ b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java @@ -5,10 +5,10 @@ package io.opentelemetry.exporter.prometheus.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.prometheus.PrometheusHttpServer; import io.opentelemetry.exporter.prometheus.PrometheusHttpServerBuilder; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.metrics.export.MetricReader; /** @@ -30,7 +30,7 @@ public String getName() { } @Override - public MetricReader create(StructuredConfigProperties config) { + public MetricReader create(DeclarativeConfigProperties config) { PrometheusHttpServerBuilder prometheusBuilder = PrometheusHttpServer.builder(); Integer port = config.getInt("port"); diff --git a/exporters/zipkin/build.gradle.kts b/exporters/zipkin/build.gradle.kts index ade51707932..1636cd7ace8 100644 --- a/exporters/zipkin/build.gradle.kts +++ b/exporters/zipkin/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { implementation(project(":exporters:common")) implementation(project(":sdk-extensions:autoconfigure-spi")) + compileOnly(project(":api:incubator")) implementation("io.zipkin.reporter2:zipkin-sender-okhttp3") diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java index eafd62479f0..b1dc3bf25af 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java @@ -5,10 +5,10 @@ package io.opentelemetry.exporter.zipkin.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.trace.export.SpanExporter; import java.time.Duration; @@ -30,7 +30,7 @@ public String getName() { } @Override - public SpanExporter create(StructuredConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config) { ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder(); String endpoint = config.getString("endpoint"); diff --git a/extensions/trace-propagators/build.gradle.kts b/extensions/trace-propagators/build.gradle.kts index 0683986978d..8ede73f0b0e 100644 --- a/extensions/trace-propagators/build.gradle.kts +++ b/extensions/trace-propagators/build.gradle.kts @@ -12,6 +12,7 @@ otelJava.moduleName.set("io.opentelemetry.extension.trace.propagation") dependencies { api(project(":api:all")) + compileOnly(project(":api:incubator")) compileOnly(project(":sdk-extensions:autoconfigure-spi")) testImplementation("io.jaegertracing:jaeger-client") diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java index b97134eda7a..d4037fba6d3 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java @@ -5,10 +5,10 @@ package io.opentelemetry.extension.trace.propagation.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.extension.trace.propagation.B3Propagator; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; /** * File configuration SPI implementation for {@link B3Propagator} which allows enables the {@link @@ -30,7 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create(StructuredConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return B3Propagator.injectingSingleHeader(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java index 77ac501a2ea..8bf8cbebe19 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java @@ -5,10 +5,10 @@ package io.opentelemetry.extension.trace.propagation.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.extension.trace.propagation.B3Propagator; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; /** * File configuration SPI implementation for {@link B3Propagator} which allows enables the {@link @@ -30,7 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create(StructuredConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return B3Propagator.injectingMultiHeaders(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java index 0fb844a40da..dff9e62cb0f 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java @@ -5,10 +5,10 @@ package io.opentelemetry.extension.trace.propagation.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.extension.trace.propagation.JaegerPropagator; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; /** * File configuration SPI implementation for {@link JaegerPropagator}. @@ -29,7 +29,7 @@ public String getName() { } @Override - public TextMapPropagator create(StructuredConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return JaegerPropagator.getInstance(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java index 97b41aad3af..490730f9ce5 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java @@ -5,11 +5,11 @@ package io.opentelemetry.extension.trace.propagation.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.extension.trace.propagation.B3Propagator; import io.opentelemetry.extension.trace.propagation.OtTracePropagator; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; /** * File configuration SPI implementation for {@link B3Propagator}. @@ -30,7 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create(StructuredConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return OtTracePropagator.getInstance(); } } diff --git a/sdk-extensions/autoconfigure-spi/build.gradle.kts b/sdk-extensions/autoconfigure-spi/build.gradle.kts index 53b10f0a104..32985cdf4e9 100644 --- a/sdk-extensions/autoconfigure-spi/build.gradle.kts +++ b/sdk-extensions/autoconfigure-spi/build.gradle.kts @@ -8,4 +8,5 @@ otelJava.moduleName.set("io.opentelemetry.sdk.autoconfigure.spi") dependencies { api(project(":sdk:all")) + compileOnly(project(":api:incubator")) } 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 335c9a7c0ab..01e91043684 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,6 +5,7 @@ package io.opentelemetry.sdk.autoconfigure.spi.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.export.LogRecordExporter; @@ -16,12 +17,12 @@ /** * 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 + * extension components which are not part of the core SDK to be referenced in declarative * 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}. + * used, and {@link #create(DeclarativeConfigProperties)} is (currently) called with an empty {@link + * DeclarativeConfigProperties}. * * @param the type of the SDK extension component. See {@link #getType()}. Supported values * include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}, {@link @@ -55,5 +56,5 @@ public interface ComponentProvider { */ // TODO (jack-berg): consider dynamic configuration use case before stabilizing in case that // affects any API decisions - T create(StructuredConfigProperties config); + T create(DeclarativeConfigProperties config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdk.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdk.java index 6751da7ad7f..9fe07eac038 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdk.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdk.java @@ -8,9 +8,9 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.incubator.config.ConfigProvider; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.resources.Resource; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -48,9 +48,8 @@ static AutoConfiguredOpenTelemetrySdk create( OpenTelemetrySdk sdk, Resource resource, @Nullable ConfigProperties config, - @Nullable StructuredConfigProperties structuredConfigProperties) { - return new AutoValue_AutoConfiguredOpenTelemetrySdk( - sdk, resource, config, structuredConfigProperties); + @Nullable ConfigProvider configProvider) { + return new AutoValue_AutoConfiguredOpenTelemetrySdk(sdk, resource, config, configProvider); } /** @@ -67,22 +66,22 @@ static AutoConfiguredOpenTelemetrySdk create( abstract Resource getResource(); /** - * Returns the {@link ConfigProperties} used for auto-configuration, or {@code null} if file - * configuration was used. + * Returns the {@link ConfigProperties} used for auto-configuration, or {@code null} if + * declarative configuration was used. * - * @see #getStructuredConfig() + * @see #getConfigProvider() */ @Nullable abstract ConfigProperties getConfig(); /** - * Returns the {@link StructuredConfigProperties} used for auto-configuration, or {@code null} if - * file configuration was not used. + * Returns the {@link ConfigProvider} representing the config used for auto-configuration, or + * {@code null} if declarative configuration was not used. * * @see #getConfig() */ @Nullable - abstract StructuredConfigProperties getStructuredConfig(); + abstract ConfigProvider getConfigProvider(); AutoConfiguredOpenTelemetrySdk() {} } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 030045ea52d..52c434aec7b 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -8,6 +8,9 @@ import static java.util.Objects.requireNonNull; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.incubator.config.ConfigProvider; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.GlobalConfigProvider; import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.TextMapPropagator; @@ -21,7 +24,6 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; @@ -49,6 +51,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; @@ -433,7 +437,10 @@ public AutoConfiguredOpenTelemetrySdk build() { maybeConfigureFromFile(config, componentLoader); if (fromFileConfiguration != null) { maybeRegisterShutdownHook(fromFileConfiguration.getOpenTelemetrySdk()); - maybeSetAsGlobal(fromFileConfiguration.getOpenTelemetrySdk()); + maybeSetAsGlobal( + fromFileConfiguration.getOpenTelemetrySdk(), + Optional.ofNullable(fromFileConfiguration.getConfigProvider()) + .orElse(ConfigProvider.noop())); return fromFileConfiguration; } @@ -505,7 +512,7 @@ public AutoConfiguredOpenTelemetrySdk build() { } maybeRegisterShutdownHook(openTelemetrySdk); - maybeSetAsGlobal(openTelemetrySdk); + maybeSetAsGlobal(openTelemetrySdk, ConfigProvider.noop()); callAutoConfigureListeners(spiHelper, openTelemetrySdk); return AutoConfiguredOpenTelemetrySdk.create(openTelemetrySdk, resource, config, null); @@ -548,38 +555,46 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile( throw new ConfigurationException("Configuration file not found", e); } try { - Class configurationFactory = - Class.forName("io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfiguration"); - Method parse = configurationFactory.getMethod("parse", InputStream.class); + Class declarativeConfiguration = + Class.forName( + "io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration"); + Method parse = declarativeConfiguration.getMethod("parse", InputStream.class); Object model = parse.invoke(null, fis); Class openTelemetryConfiguration = Class.forName( "io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel"); Method create = - configurationFactory.getMethod( + declarativeConfiguration.getMethod( "create", openTelemetryConfiguration, ComponentLoader.class); OpenTelemetrySdk sdk = (OpenTelemetrySdk) create.invoke(null, model, componentLoader); - Method toConfigProperties = - configurationFactory.getMethod("toConfigProperties", openTelemetryConfiguration); - StructuredConfigProperties structuredConfigProperties = - (StructuredConfigProperties) toConfigProperties.invoke(null, model); + Class sdkConfigProvider = + Class.forName("io.opentelemetry.sdk.extension.incubator.fileconfig.SdkConfigProvider"); + Method createFileConfigProvider = + sdkConfigProvider.getMethod("create", openTelemetryConfiguration); + ConfigProvider configProvider = (ConfigProvider) createFileConfigProvider.invoke(null, model); // Note: can't access file configuration resource without reflection so setting a dummy // resource return AutoConfiguredOpenTelemetrySdk.create( - sdk, Resource.getDefault(), null, structuredConfigProperties); + sdk, Resource.getDefault(), null, configProvider); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { throw new ConfigurationException( "Error configuring from file. Is opentelemetry-sdk-extension-incubator on the classpath?", e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); - if (cause instanceof ConfigurationException) { - throw (ConfigurationException) cause; + if (cause instanceof DeclarativeConfigException) { + throw toConfigurationException((DeclarativeConfigException) cause); } throw new ConfigurationException("Unexpected error configuring from file", e); } } + private static ConfigurationException toConfigurationException( + DeclarativeConfigException exception) { + String message = Objects.requireNonNull(exception.getMessage()); + return new ConfigurationException(message, exception); + } + private void maybeRegisterShutdownHook(OpenTelemetrySdk openTelemetrySdk) { if (!registerShutdownHook) { return; @@ -587,13 +602,14 @@ private void maybeRegisterShutdownHook(OpenTelemetrySdk openTelemetrySdk) { Runtime.getRuntime().addShutdownHook(shutdownHook(openTelemetrySdk)); } - private void maybeSetAsGlobal(OpenTelemetrySdk openTelemetrySdk) { + private void maybeSetAsGlobal(OpenTelemetrySdk openTelemetrySdk, ConfigProvider configProvider) { if (!setResultAsGlobal) { return; } GlobalOpenTelemetry.set(openTelemetrySdk); GlobalEventLoggerProvider.set( SdkEventLoggerProvider.create(openTelemetrySdk.getSdkLoggerProvider())); + GlobalConfigProvider.set(configProvider); logger.log( Level.FINE, "Global OpenTelemetry set to {0} by autoconfiguration", openTelemetrySdk); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java index fe18ac8d41b..52f0236e8d2 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java @@ -5,10 +5,10 @@ package io.opentelemetry.sdk.autoconfigure.internal; +import io.opentelemetry.api.incubator.config.ConfigProvider; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.function.Function; @@ -25,7 +25,7 @@ private AutoConfigureUtil() {} /** * Returns the {@link ConfigProperties} used for auto-configuration. * - * @return the config properties, or {@code null} if file based configuration is used + * @return the config properties, or {@code null} if declarative configuration is used */ @Nullable public static ConfigProperties getConfig( @@ -41,21 +41,21 @@ public static ConfigProperties getConfig( } /** - * Returns the {@link StructuredConfigProperties} used for auto-configuration when file based + * Returns the {@link ConfigProvider} resulting from auto-configuration when declarative * configuration is used. * - * @return the config properties, or {@code null} if file based configuration is NOT used + * @return the {@link ConfigProvider}, or {@code null} if declarative configuration is NOT used */ @Nullable - public static StructuredConfigProperties getStructuredConfig( + public static ConfigProvider getConfigProvider( AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) { try { - Method method = AutoConfiguredOpenTelemetrySdk.class.getDeclaredMethod("getStructuredConfig"); + Method method = AutoConfiguredOpenTelemetrySdk.class.getDeclaredMethod("getConfigProvider"); method.setAccessible(true); - return (StructuredConfigProperties) method.invoke(autoConfiguredOpenTelemetrySdk); + return (ConfigProvider) method.invoke(autoConfiguredOpenTelemetrySdk); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException( - "Error calling getStructuredConfig on AutoConfiguredOpenTelemetrySdk", e); + "Error calling getConfigProvider on AutoConfiguredOpenTelemetrySdk", e); } } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 6f3196a6f61..48af0c614b4 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -5,12 +5,12 @@ package io.opentelemetry.sdk.autoconfigure.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -93,13 +93,13 @@ public NamedSpiManager loadConfigurable( /** * Find a registered {@link ComponentProvider} with {@link ComponentProvider#getType()} matching * {@code type}, {@link ComponentProvider#getName()} matching {@code name}, and call {@link - * ComponentProvider#create(StructuredConfigProperties)} with the given {@code config}. + * ComponentProvider#create(DeclarativeConfigProperties)} with the given {@code config}. * - * @throws ConfigurationException if no matching providers are found, or if multiple are found - * (i.e. conflict), or if {@link ComponentProvider#create(StructuredConfigProperties)} throws + * @throws DeclarativeConfigException if no matching providers are found, or if multiple are found + * (i.e. conflict), or if {@link ComponentProvider#create(DeclarativeConfigProperties)} throws */ @SuppressWarnings({"unchecked", "rawtypes"}) - public T loadComponent(Class type, String name, StructuredConfigProperties config) { + public T loadComponent(Class type, String name, DeclarativeConfigProperties config) { // TODO(jack-berg): cache loaded component providers List componentProviders = load(ComponentProvider.class); List> matchedProviders = @@ -112,11 +112,11 @@ public T loadComponent(Class type, String name, StructuredConfigPropertie componentProvider.getType() == type && name.equals(componentProvider.getName())) .collect(Collectors.toList()); if (matchedProviders.isEmpty()) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "No component provider detected for " + type.getName() + " with name \"" + name + "\"."); } if (matchedProviders.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Component provider conflict. Multiple providers detected for " + type.getName() + " with name \"" @@ -132,7 +132,7 @@ public T loadComponent(Class type, String name, StructuredConfigPropertie try { return provider.create(config); } catch (Throwable throwable) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Error configuring " + type.getName() + " with name \"" + name + "\"", throwable); } } diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FileConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/DeclarativeConfigurationTest.java similarity index 81% rename from sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FileConfigurationTest.java rename to sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/DeclarativeConfigurationTest.java index 3b3869e5bf6..828aae3637c 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FileConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/DeclarativeConfigurationTest.java @@ -17,14 +17,18 @@ import io.github.netmikey.logunit.api.LogCapturer; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.incubator.config.ConfigProvider; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; +import io.opentelemetry.api.incubator.config.GlobalConfigProvider; +import io.opentelemetry.api.incubator.config.InstrumentationConfigUtil; import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; @@ -33,6 +37,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,7 +45,7 @@ import org.junit.jupiter.api.io.TempDir; import org.slf4j.event.Level; -class FileConfigurationTest { +class DeclarativeConfigurationTest { @RegisterExtension private static final CleanupExtension cleanup = new CleanupExtension(); @@ -65,14 +70,21 @@ void setup() throws IOException { + " - simple:\n" + " exporter:\n" + " console: {}\n" - + "other:\n" - + " str_key: str_value\n" - + " map_key:\n" - + " str_key1: str_value1\n"; + + "instrumentation:\n" + + " general:\n" + + " http:\n" + + " client:\n" + + " request_captured_headers:\n" + + " - Content-Type\n" + + " - Accept\n" + + " java:\n" + + " example:\n" + + " key: value\n"; configFilePath = tempDir.resolve("otel-config.yaml"); Files.write(configFilePath, yaml.getBytes(StandardCharsets.UTF_8)); GlobalOpenTelemetry.resetForTest(); GlobalEventLoggerProvider.resetForTest(); + GlobalConfigProvider.resetForTest(); } @Test @@ -137,6 +149,8 @@ void configFile_setResultAsGlobalFalse() { assertThat(GlobalOpenTelemetry.get()).extracting("delegate").isNotSameAs(openTelemetrySdk); assertThat(GlobalEventLoggerProvider.get()) .isNotSameAs(openTelemetrySdk.getSdkLoggerProvider()); + assertThat(GlobalConfigProvider.get()) + .isNotSameAs(autoConfiguredOpenTelemetrySdk.getConfigProvider()); } @Test @@ -155,6 +169,8 @@ void configFile_setResultAsGlobalTrue() { .isInstanceOf(SdkEventLoggerProvider.class) .extracting("delegateLoggerProvider") .isSameAs(openTelemetrySdk.getSdkLoggerProvider()); + assertThat(GlobalConfigProvider.get()) + .isSameAs(autoConfiguredOpenTelemetrySdk.getConfigProvider()); } @Test @@ -183,7 +199,7 @@ void configFile_Error(@TempDir Path tempDir) throws IOException { } @Test - void configFile_StructuredConfigProperties() { + void configFile_ConfigProvider() { ConfigProperties config = DefaultConfigProperties.createFromMap( Collections.singletonMap("otel.experimental.config.file", configFilePath.toString())); @@ -194,14 +210,19 @@ void configFile_StructuredConfigProperties() { cleanup.addCloseable(openTelemetrySdk); // getConfig() should return ExtendedConfigProperties generic representation of the config file - StructuredConfigProperties structuredConfigProps = - autoConfiguredOpenTelemetrySdk.getStructuredConfig(); - assertThat(structuredConfigProps).isNotNull(); - StructuredConfigProperties otherProps = structuredConfigProps.getStructured("other"); - assertThat(otherProps).isNotNull(); - assertThat(otherProps.getString("str_key")).isEqualTo("str_value"); - StructuredConfigProperties otherMapKeyProps = otherProps.getStructured("map_key"); - assertThat(otherMapKeyProps).isNotNull(); - assertThat(otherMapKeyProps.getString("str_key1")).isEqualTo("str_value1"); + ConfigProvider globalConfigProvider = GlobalConfigProvider.get(); + assertThat(globalConfigProvider) + .isNotNull() + .isSameAs(AutoConfigureUtil.getConfigProvider(autoConfiguredOpenTelemetrySdk)); + DeclarativeConfigProperties instrumentationConfig = + globalConfigProvider.getInstrumentationConfig(); + assertThat(instrumentationConfig).isNotNull(); + + // Extract instrumentation config from ConfigProvider + assertThat(InstrumentationConfigUtil.httpClientRequestCapturedHeaders(globalConfigProvider)) + .isEqualTo(Arrays.asList("Content-Type", "Accept")); + assertThat(InstrumentationConfigUtil.javaInstrumentationConfig(globalConfigProvider, "example")) + .isNotNull() + .satisfies(exampleConfig -> assertThat(exampleConfig.getString("key")).isEqualTo("value")); } } diff --git a/sdk-extensions/incubator/build.gradle.kts b/sdk-extensions/incubator/build.gradle.kts index 59acac261ef..006f584f09f 100644 --- a/sdk-extensions/incubator/build.gradle.kts +++ b/sdk-extensions/incubator/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { implementation("org.snakeyaml:snakeyaml-engine") // io.opentelemetry.sdk.extension.incubator.fileconfig + implementation(project(":api:incubator")) implementation("com.fasterxml.jackson.core:jackson-databind") api("com.fasterxml.jackson.core:jackson-annotations") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactory.java index 6e35ecbdbfb..984107d9027 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactory.java @@ -5,8 +5,8 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AggregationModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Base2ExponentialBucketHistogramModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExplicitBucketHistogramModel; @@ -51,7 +51,7 @@ public io.opentelemetry.sdk.metrics.Aggregation create( return io.opentelemetry.sdk.metrics.Aggregation.base2ExponentialBucketHistogram( maxSize, maxScale); } catch (IllegalArgumentException e) { - throw new ConfigurationException("Invalid exponential bucket histogram", e); + throw new DeclarativeConfigException("Invalid exponential bucket histogram", e); } } ExplicitBucketHistogramModel explicitBucketHistogram = model.getExplicitBucketHistogram(); @@ -63,7 +63,7 @@ public io.opentelemetry.sdk.metrics.Aggregation create( try { return io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram(boundaries); } catch (IllegalArgumentException e) { - throw new ConfigurationException("Invalid explicit bucket histogram", e); + throw new DeclarativeConfigException("Invalid explicit bucket histogram", e); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactory.java index c3bba8925b3..1f39f5a1d80 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactory.java @@ -9,8 +9,8 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel; import java.io.Closeable; import java.util.List; @@ -115,7 +115,7 @@ private static void addToBuilder( } break; } - throw new ConfigurationException( + throw new DeclarativeConfigException( "Error processing attribute with name \"" + name + "\": value did not match type " 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/DeclarativeConfiguration.java similarity index 78% rename from sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java rename to sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfiguration.java index 76cf9cc1fbe..7bccdc4bf24 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/DeclarativeConfiguration.java @@ -9,12 +9,12 @@ import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SamplerModel; import java.io.Closeable; @@ -40,18 +40,20 @@ import org.snakeyaml.engine.v2.schema.CoreSchema; /** - * Configure {@link OpenTelemetrySdk} from YAML configuration files conforming to the schema in open-telemetry/opentelemetry-configuration. - * - * @see #parseAndCreate(InputStream) + * Configure {@link OpenTelemetrySdk} using declarative + * configuration. For most users, this means calling {@link #parseAndCreate(InputStream)} with a + * YAML + * configuration file. */ -public final class FileConfiguration { +public final class DeclarativeConfiguration { - private static final Logger logger = Logger.getLogger(FileConfiguration.class.getName()); + private static final Logger logger = Logger.getLogger(DeclarativeConfiguration.class.getName()); private static final Pattern ENV_VARIABLE_REFERENCE = Pattern.compile("\\$\\{([a-zA-Z_][a-zA-Z0-9_]*)(:-([^\n]*))?\\}"); private static final ComponentLoader DEFAULT_COMPONENT_LOADER = - SpiHelper.serviceComponentLoader(FileConfiguration.class.getClassLoader()); + SpiHelper.serviceComponentLoader(DeclarativeConfiguration.class.getClassLoader()); private static final ObjectMapper MAPPER; @@ -68,12 +70,12 @@ public final class FileConfiguration { MAPPER.configOverride(Boolean.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET)); } - private FileConfiguration() {} + private DeclarativeConfiguration() {} /** * Combines {@link #parse(InputStream)} and {@link #create(OpenTelemetryConfigurationModel)}. * - * @throws ConfigurationException if unable to parse or interpret + * @throws DeclarativeConfigException if unable to parse or interpret */ public static OpenTelemetrySdk parseAndCreate(InputStream inputStream) { OpenTelemetryConfigurationModel configurationModel = parse(inputStream); @@ -86,7 +88,7 @@ public static OpenTelemetrySdk parseAndCreate(InputStream inputStream) { * * @param configurationModel the configuration model * @return the {@link OpenTelemetrySdk} - * @throws ConfigurationException if unable to interpret + * @throws DeclarativeConfigException if unable to interpret */ public static OpenTelemetrySdk create(OpenTelemetryConfigurationModel configurationModel) { return create(configurationModel, DEFAULT_COMPONENT_LOADER); @@ -100,7 +102,7 @@ public static OpenTelemetrySdk create(OpenTelemetryConfigurationModel configurat * @param componentLoader the component loader used to load {@link ComponentProvider} * implementations * @return the {@link OpenTelemetrySdk} - * @throws ConfigurationException if unable to interpret + * @throws DeclarativeConfigException if unable to interpret */ public static OpenTelemetrySdk create( OpenTelemetryConfigurationModel configurationModel, ComponentLoader componentLoader) { @@ -116,13 +118,13 @@ public static OpenTelemetrySdk create( *

Before parsing, environment variable substitution is performed as described in {@link * EnvSubstitutionConstructor}. * - * @throws ConfigurationException if unable to parse + * @throws DeclarativeConfigException if unable to parse */ public static OpenTelemetryConfigurationModel parse(InputStream configuration) { try { return parse(configuration, System.getenv()); } catch (RuntimeException e) { - throw new ConfigurationException("Unable to parse configuration input stream", e); + throw new DeclarativeConfigException("Unable to parse configuration input stream", e); } } @@ -141,32 +143,32 @@ static Object loadYaml(InputStream inputStream, Map environmentV } /** - * Convert the {@code model} to a generic {@link StructuredConfigProperties}. + * Convert the {@code model} to a generic {@link DeclarativeConfigProperties}. * * @param model the configuration model - * @return a generic {@link StructuredConfigProperties} representation of the model + * @return a generic {@link DeclarativeConfigProperties} representation of the model */ - public static StructuredConfigProperties toConfigProperties( + public static DeclarativeConfigProperties toConfigProperties( OpenTelemetryConfigurationModel model) { return toConfigProperties(model, DEFAULT_COMPONENT_LOADER); } /** - * Convert the {@code configuration} YAML to a generic {@link StructuredConfigProperties}. + * Convert the {@code configuration} YAML to a generic {@link DeclarativeConfigProperties}. * * @param configuration configuration YAML - * @return a generic {@link StructuredConfigProperties} representation of the model + * @return a generic {@link DeclarativeConfigProperties} representation of the model */ - public static StructuredConfigProperties toConfigProperties(InputStream configuration) { + public static DeclarativeConfigProperties toConfigProperties(InputStream configuration) { Object yamlObj = loadYaml(configuration, System.getenv()); return toConfigProperties(yamlObj, DEFAULT_COMPONENT_LOADER); } - static StructuredConfigProperties toConfigProperties( + static DeclarativeConfigProperties toConfigProperties( Object model, ComponentLoader componentLoader) { Map configurationMap = MAPPER.convertValue(model, new TypeReference>() {}); - return YamlStructuredConfigProperties.create(configurationMap, componentLoader); + return YamlDeclarativeConfigProperties.create(configurationMap, componentLoader); } /** @@ -174,34 +176,34 @@ static StructuredConfigProperties toConfigProperties( * *

This is used when samplers are composed, with one sampler accepting one or more additional * samplers as config properties. The {@link ComponentProvider} implementation can call this to - * configure a delegate {@link SamplerModel} from the {@link StructuredConfigProperties} + * configure a delegate {@link SamplerModel} from the {@link DeclarativeConfigProperties} * corresponding to a particular config property. */ // TODO(jack-berg): add create methods for all SDK extension components supported by // ComponentProvider public static io.opentelemetry.sdk.trace.samplers.Sampler createSampler( - StructuredConfigProperties genericSamplerModel) { - YamlStructuredConfigProperties yamlStructuredConfigProperties = - requireYamlStructuredConfigProperties(genericSamplerModel); - SamplerModel samplerModel = convertToModel(yamlStructuredConfigProperties, SamplerModel.class); + DeclarativeConfigProperties genericSamplerModel) { + YamlDeclarativeConfigProperties yamlDeclarativeConfigProperties = + requireYamlDeclarativeConfigProperties(genericSamplerModel); + SamplerModel samplerModel = convertToModel(yamlDeclarativeConfigProperties, SamplerModel.class); return createAndMaybeCleanup( SamplerFactory.getInstance(), - SpiHelper.create(yamlStructuredConfigProperties.getComponentLoader()), + SpiHelper.create(yamlDeclarativeConfigProperties.getComponentLoader()), samplerModel); } - private static YamlStructuredConfigProperties requireYamlStructuredConfigProperties( - StructuredConfigProperties structuredConfigProperties) { - if (!(structuredConfigProperties instanceof YamlStructuredConfigProperties)) { - throw new ConfigurationException( - "Only YamlStructuredConfigProperties can be converted to model"); + private static YamlDeclarativeConfigProperties requireYamlDeclarativeConfigProperties( + DeclarativeConfigProperties declarativeConfigProperties) { + if (!(declarativeConfigProperties instanceof YamlDeclarativeConfigProperties)) { + throw new DeclarativeConfigException( + "Only YamlDeclarativeConfigProperties can be converted to model"); } - return (YamlStructuredConfigProperties) structuredConfigProperties; + return (YamlDeclarativeConfigProperties) declarativeConfigProperties; } static T convertToModel( - YamlStructuredConfigProperties structuredConfigProperties, Class modelType) { - return MAPPER.convertValue(structuredConfigProperties.toMap(), modelType); + YamlDeclarativeConfigProperties yamlDeclarativeConfigProperties, Class modelType) { + return MAPPER.convertValue(yamlDeclarativeConfigProperties.toMap(), modelType); } static R createAndMaybeCleanup(Factory factory, SpiHelper spiHelper, M model) { @@ -219,10 +221,10 @@ static R createAndMaybeCleanup(Factory factory, SpiHelper spiHelper "Error closing " + closeable.getClass().getName() + ": " + ex.getMessage()); } } - if (e instanceof ConfigurationException) { + if (e instanceof DeclarativeConfigException) { throw e; } - throw new ConfigurationException("Unexpected configuration error", e); + throw new DeclarativeConfigException("Unexpected configuration error", e); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigUtil.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigUtil.java index f4c1346dc72..1c8944d7097 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigUtil.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigUtil.java @@ -5,10 +5,10 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import java.io.Closeable; import java.util.List; import javax.annotation.Nullable; @@ -34,7 +34,7 @@ static T assertNotNull(@Nullable T object, String description) { static T requireNonNull(@Nullable T object, String description) { if (object == null) { - throw new ConfigurationException(description + " is required but is null"); + throw new DeclarativeConfigException(description + " is required but is null"); } return object; } @@ -42,15 +42,15 @@ static T requireNonNull(@Nullable T object, String description) { /** * Find a registered {@link ComponentProvider} which {@link ComponentProvider#getType()} matching * {@code type}, {@link ComponentProvider#getName()} matching {@code name}, and call {@link - * ComponentProvider#create(StructuredConfigProperties)} with the given {@code model}. + * ComponentProvider#create(DeclarativeConfigProperties)} with the given {@code model}. * - * @throws ConfigurationException if no matching providers are found, or if multiple are found - * (i.e. conflict), or if {@link ComponentProvider#create(StructuredConfigProperties)} throws + * @throws DeclarativeConfigException if no matching providers are found, or if multiple are found + * (i.e. conflict), or if {@link ComponentProvider#create(DeclarativeConfigProperties)} throws */ static T loadComponent(SpiHelper spiHelper, Class type, String name, Object model) { // Map model to generic structured config properties - StructuredConfigProperties config = - FileConfiguration.toConfigProperties(model, spiHelper.getComponentLoader()); + DeclarativeConfigProperties config = + DeclarativeConfiguration.toConfigProperties(model, spiHelper.getComponentLoader()); return spiHelper.loadComponent(type, name, config); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactory.java index 767908c6595..d45d1ac3218 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactory.java @@ -5,8 +5,8 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SelectorModel; import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.InstrumentSelectorBuilder; @@ -36,7 +36,7 @@ public InstrumentSelector create( try { instrumentType = InstrumentType.valueOf(model.getInstrumentType().name()); } catch (IllegalArgumentException e) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Unrecognized instrument type: " + model.getInstrumentType(), e); } builder.setType(instrumentType); @@ -54,7 +54,7 @@ public InstrumentSelector create( try { return builder.build(); } catch (IllegalArgumentException e) { - throw new ConfigurationException("Invalid selector", e); + throw new DeclarativeConfigException("Invalid selector", e); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java index e006befe0f7..1af81a7e7f6 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java @@ -7,8 +7,8 @@ import static java.util.stream.Collectors.joining; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ConsoleModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpModel; @@ -43,7 +43,7 @@ public LogRecordExporter create( if (!model.getAdditionalProperties().isEmpty()) { Map additionalProperties = model.getAdditionalProperties(); if (additionalProperties.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Invalid configuration - multiple log record exporters set: " + additionalProperties.keySet().stream().collect(joining(",", "[", "]"))); } @@ -61,7 +61,7 @@ public LogRecordExporter create( exporterKeyValue.getValue()); return FileConfigUtil.addAndReturn(closeables, logRecordExporter); } else { - throw new ConfigurationException("log exporter must be set"); + throw new DeclarativeConfigException("log exporter must be set"); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java index a9cec70455a..9f090c9c441 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java @@ -7,8 +7,8 @@ import static java.util.stream.Collectors.joining; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchLogRecordProcessorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordProcessorModel; @@ -74,7 +74,7 @@ public LogRecordProcessor create( if (!model.getAdditionalProperties().isEmpty()) { Map additionalProperties = model.getAdditionalProperties(); if (additionalProperties.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Invalid configuration - multiple log record processors set: " + additionalProperties.keySet().stream().collect(joining(",", "[", "]"))); } @@ -92,7 +92,7 @@ public LogRecordProcessor create( processorKeyValue.getValue()); return FileConfigUtil.addAndReturn(closeables, logRecordProcessor); } else { - throw new ConfigurationException("log processor must be set"); + throw new DeclarativeConfigException("log processor must be set"); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java index 6d9616f8524..0b5e12aab8e 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java @@ -7,8 +7,8 @@ import static java.util.stream.Collectors.joining; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpMetricModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PushMetricExporterModel; import io.opentelemetry.sdk.metrics.export.MetricExporter; @@ -41,7 +41,7 @@ public MetricExporter create( if (!model.getAdditionalProperties().isEmpty()) { Map additionalProperties = model.getAdditionalProperties(); if (additionalProperties.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Invalid configuration - multiple metric exporters set: " + additionalProperties.keySet().stream().collect(joining(",", "[", "]"))); } @@ -59,7 +59,7 @@ public MetricExporter create( exporterKeyValue.getValue()); return FileConfigUtil.addAndReturn(closeables, metricExporter); } else { - throw new ConfigurationException("metric exporter must be set"); + throw new DeclarativeConfigException("metric exporter must be set"); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java index c30ac774b60..2fc7479920b 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java @@ -7,8 +7,8 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigUtil.requireNonNull; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.MetricReaderModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PeriodicMetricReaderModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PrometheusModel; @@ -61,9 +61,10 @@ public MetricReader create( return FileConfigUtil.addAndReturn(closeables, metricReader); } - throw new ConfigurationException("prometheus is the only currently supported pull reader"); + throw new DeclarativeConfigException( + "prometheus is the only currently supported pull reader"); } - throw new ConfigurationException("reader must be set"); + throw new DeclarativeConfigException("reader must be set"); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java index 0213839ee30..a993a6fc7c2 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactory.java @@ -5,10 +5,10 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.OpenTelemetrySdkBuilder; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; import io.opentelemetry.sdk.resources.Resource; import java.io.Closeable; @@ -32,7 +32,8 @@ public OpenTelemetrySdk create( OpenTelemetryConfigurationModel model, SpiHelper spiHelper, List closeables) { OpenTelemetrySdkBuilder builder = OpenTelemetrySdk.builder(); if (!"0.1".equals(model.getFileFormat())) { - throw new ConfigurationException("Unsupported file format. Supported formats include: 0.1"); + throw new DeclarativeConfigException( + "Unsupported file format. Supported formats include: 0.1"); } if (Objects.equals(Boolean.TRUE, model.getDisabled())) { diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceFactory.java index 8f26e6a47e7..f9d2c8e80b6 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceFactory.java @@ -7,13 +7,13 @@ import static io.opentelemetry.sdk.internal.GlobUtil.toGlobPatternPredicate; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.ResourceConfiguration; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.DetectorAttributesModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.DetectorsModel; @@ -33,10 +33,6 @@ final class ResourceFactory io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ResourceModel, Resource> { - private static final StructuredConfigProperties EMPTY_CONFIG = - FileConfiguration.toConfigProperties( - Collections.emptyMap(), - SpiHelper.serviceComponentLoader(ResourceFactory.class.getClassLoader())); private static final ResourceFactory INSTANCE = new ResourceFactory(); private ResourceFactory() {} @@ -91,7 +87,7 @@ public Resource create( *

In file configuration, a resource detector is a {@link ComponentProvider} with {@link * ComponentProvider#getType()} set to {@link Resource}. Unlike other {@link ComponentProvider}s, * the resource detector version does not use {@link ComponentProvider#getName()} (except for - * debug messages), and {@link ComponentProvider#create(StructuredConfigProperties)} is called + * debug messages), and {@link ComponentProvider#create(DeclarativeConfigProperties)} is called * with an empty instance. Additionally, the {@link Ordered#order()} value is respected for * resource detectors which implement {@link Ordered}. */ @@ -105,9 +101,9 @@ private static List loadFromResourceDetectors(SpiHelper spiHelper) { } Resource resource; try { - resource = (Resource) componentProvider.create(EMPTY_CONFIG); + resource = (Resource) componentProvider.create(DeclarativeConfigProperties.empty()); } catch (Throwable throwable) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Error configuring " + Resource.class.getName() + " with name \"" diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java index 0b38631e0db..491355418ec 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java @@ -7,8 +7,8 @@ import static java.util.stream.Collectors.joining; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.JaegerRemoteModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ParentBasedModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SamplerModel; @@ -81,7 +81,7 @@ public Sampler create(SamplerModel model, SpiHelper spiHelper, List c if (!model.getAdditionalProperties().isEmpty()) { Map additionalProperties = model.getAdditionalProperties(); if (additionalProperties.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Invalid configuration - multiple samplers exporters set: " + additionalProperties.keySet().stream().collect(joining(",", "[", "]"))); } @@ -95,7 +95,7 @@ public Sampler create(SamplerModel model, SpiHelper spiHelper, List c spiHelper, Sampler.class, exporterKeyValue.getKey(), exporterKeyValue.getValue()); return FileConfigUtil.addAndReturn(closeables, sampler); } else { - throw new ConfigurationException("sampler must be set"); + throw new DeclarativeConfigException("sampler must be set"); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SdkConfigProvider.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SdkConfigProvider.java new file mode 100644 index 00000000000..8c8d549e007 --- /dev/null +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SdkConfigProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.extension.incubator.fileconfig; + +import io.opentelemetry.api.incubator.config.ConfigProvider; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; +import javax.annotation.Nullable; + +/** SDK implementation of {@link ConfigProvider}. */ +public final class SdkConfigProvider implements ConfigProvider { + + @Nullable private final DeclarativeConfigProperties instrumentationConfig; + + private SdkConfigProvider(OpenTelemetryConfigurationModel model) { + DeclarativeConfigProperties configProperties = + DeclarativeConfiguration.toConfigProperties(model); + this.instrumentationConfig = configProperties.getStructured("instrumentation"); + } + + /** + * Create a {@link SdkConfigProvider} from the {@code model}. + * + * @param model the configuration model + * @return the {@link SdkConfigProvider} + */ + public static SdkConfigProvider create(OpenTelemetryConfigurationModel model) { + return new SdkConfigProvider(model); + } + + @Nullable + @Override + public DeclarativeConfigProperties getInstrumentationConfig() { + return instrumentationConfig; + } +} diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java index 652b3917acf..a984c109033 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java @@ -7,8 +7,8 @@ import static java.util.stream.Collectors.joining; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ZipkinModel; @@ -47,7 +47,7 @@ public SpanExporter create( if (!model.getAdditionalProperties().isEmpty()) { Map additionalProperties = model.getAdditionalProperties(); if (additionalProperties.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Invalid configuration - multiple span exporters set: " + additionalProperties.keySet().stream().collect(joining(",", "[", "]"))); } @@ -65,7 +65,7 @@ public SpanExporter create( exporterKeyValue.getValue()); return FileConfigUtil.addAndReturn(closeables, spanExporter); } else { - throw new ConfigurationException("span exporter must be set"); + throw new DeclarativeConfigException("span exporter must be set"); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java index 04a5a144303..506b7791f2c 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java @@ -7,8 +7,8 @@ import static java.util.stream.Collectors.joining; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchSpanProcessorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SimpleSpanProcessorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanExporterModel; @@ -70,7 +70,7 @@ public SpanProcessor create( if (!model.getAdditionalProperties().isEmpty()) { Map additionalProperties = model.getAdditionalProperties(); if (additionalProperties.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Invalid configuration - multiple span processors set: " + additionalProperties.keySet().stream().collect(joining(",", "[", "]"))); } @@ -88,7 +88,7 @@ public SpanProcessor create( processorKeyValue.getValue()); return FileConfigUtil.addAndReturn(closeables, spanProcessor); } else { - throw new ConfigurationException("span processor must be set"); + throw new DeclarativeConfigException("span processor must be set"); } } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java index b2a212aaa57..798a4b337ec 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java @@ -6,10 +6,10 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig; import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import java.io.Closeable; import java.util.ArrayList; import java.util.Arrays; @@ -35,7 +35,7 @@ public TextMapPropagator create( if (model.contains("none")) { if (model.size() > 1) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "propagators contains \"none\" along with other propagators"); } return TextMapPropagator.noop(); 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/YamlDeclarativeConfigProperties.java similarity index 76% rename from sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigProperties.java rename to sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigProperties.java index 87cbc5f8fc8..a27753fad49 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/YamlDeclarativeConfigProperties.java @@ -8,14 +8,15 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -24,26 +25,33 @@ import javax.annotation.Nullable; /** - * Implementation of {@link StructuredConfigProperties} which uses a file configuration model as a + * Implementation of {@link DeclarativeConfigProperties} which uses a file configuration model as a * source. * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + * * @see #getStructured(String) Accessing nested maps * @see #getStructuredList(String) Accessing lists of maps - * @see FileConfiguration#toConfigProperties(Object) Converting configuration model to properties */ -final class YamlStructuredConfigProperties implements StructuredConfigProperties { +public final class YamlDeclarativeConfigProperties implements DeclarativeConfigProperties { + + private static final Set> SUPPORTED_SCALAR_TYPES = + Collections.unmodifiableSet( + new LinkedHashSet<>( + Arrays.asList(String.class, Boolean.class, Long.class, Double.class))); /** Values are {@link #isPrimitive(Object)}, {@link List} of scalars. */ private final Map simpleEntries; - private final Map> listEntries; - private final Map mapEntries; + private final Map> listEntries; + private final Map mapEntries; private final ComponentLoader componentLoader; - private YamlStructuredConfigProperties( + private YamlDeclarativeConfigProperties( Map simpleEntries, - Map> listEntries, - Map mapEntries, + Map> listEntries, + Map mapEntries, ComponentLoader componentLoader) { this.simpleEntries = simpleEntries; this.listEntries = listEntries; @@ -52,20 +60,20 @@ private YamlStructuredConfigProperties( } /** - * Create a {@link YamlStructuredConfigProperties} from the {@code properties} map. + * Create a {@link YamlDeclarativeConfigProperties} from the {@code properties} map. * - *

{@code properties} is expected to be the output of YAML parsing (i.e. with Jackson {@link + *

{@code properties} is expected to be the output of YAML parsing (i.e. with Jackson {@code * com.fasterxml.jackson.databind.ObjectMapper}), and have values which are scalars, lists of * scalars, lists of maps, and maps. * - * @see FileConfiguration#toConfigProperties(OpenTelemetryConfigurationModel) + * @see DeclarativeConfiguration#toConfigProperties(OpenTelemetryConfigurationModel) */ @SuppressWarnings("unchecked") - static YamlStructuredConfigProperties create( + static YamlDeclarativeConfigProperties create( Map properties, ComponentLoader componentLoader) { - Map simpleEntries = new HashMap<>(); - Map> listEntries = new HashMap<>(); - Map mapEntries = new HashMap<>(); + Map simpleEntries = new LinkedHashMap<>(); + Map> listEntries = new LinkedHashMap<>(); + Map mapEntries = new LinkedHashMap<>(); for (Map.Entry entry : properties.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); @@ -78,34 +86,34 @@ static YamlStructuredConfigProperties create( continue; } if (isListOfMaps(value)) { - List list = + List list = ((List>) value) .stream() - .map(map -> YamlStructuredConfigProperties.create(map, componentLoader)) + .map(map -> YamlDeclarativeConfigProperties.create(map, componentLoader)) .collect(toList()); listEntries.put(key, list); continue; } if (isMap(value)) { - YamlStructuredConfigProperties configProperties = - YamlStructuredConfigProperties.create((Map) value, componentLoader); + YamlDeclarativeConfigProperties configProperties = + YamlDeclarativeConfigProperties.create((Map) value, componentLoader); mapEntries.put(key, configProperties); continue; } - throw new ConfigurationException( + throw new DeclarativeConfigException( "Unable to initialize ExtendedConfigProperties. Key \"" + key + "\" has unrecognized object type " + value.getClass().getName()); } - return new YamlStructuredConfigProperties( + return new YamlDeclarativeConfigProperties( simpleEntries, listEntries, mapEntries, componentLoader); } private static boolean isPrimitiveList(Object object) { if (object instanceof List) { List list = (List) object; - return list.stream().allMatch(YamlStructuredConfigProperties::isPrimitive); + return list.stream().allMatch(YamlDeclarativeConfigProperties::isPrimitive); } return false; } @@ -177,16 +185,12 @@ public Double getDouble(String name) { return doubleOrNull(simpleEntries.get(name)); } - private static final Set> SUPPORTED_SCALAR_TYPES = - Collections.unmodifiableSet( - new HashSet<>(Arrays.asList(String.class, Boolean.class, Long.class, Double.class))); - @Nullable @Override @SuppressWarnings("unchecked") public List getScalarList(String name, Class scalarType) { if (!SUPPORTED_SCALAR_TYPES.contains(scalarType)) { - throw new ConfigurationException( + throw new DeclarativeConfigException( "Unsupported scalar type " + scalarType.getName() + ". Supported types include " @@ -258,14 +262,14 @@ private static Double doubleOrNull(@Nullable Object value) { @Nullable @Override - public StructuredConfigProperties getStructured(String name) { + public DeclarativeConfigProperties getStructured(String name) { return mapEntries.get(name); } @Nullable @Override - public List getStructuredList(String name) { - List value = listEntries.get(name); + public List getStructuredList(String name) { + List value = listEntries.get(name); if (value != null) { return Collections.unmodifiableList(value); } @@ -274,7 +278,7 @@ public List getStructuredList(String name) { @Override public Set getPropertyKeys() { - Set keys = new HashSet<>(); + Set keys = new LinkedHashSet<>(); keys.addAll(simpleEntries.keySet()); keys.addAll(listEntries.keySet()); keys.addAll(mapEntries.keySet()); @@ -283,7 +287,7 @@ public Set getPropertyKeys() { @Override public String toString() { - StringJoiner joiner = new StringJoiner(", ", "YamlStructuredConfigProperties{", "}"); + StringJoiner joiner = new StringJoiner(", ", "YamlDeclarativeConfigProperties{", "}"); simpleEntries.forEach((key, value) -> joiner.add(key + "=" + value)); listEntries.forEach((key, value) -> joiner.add(key + "=" + value)); mapEntries.forEach((key, value) -> joiner.add(key + "=" + value)); @@ -296,7 +300,7 @@ public Map toMap() { listEntries.forEach( (key, value) -> result.put( - key, value.stream().map(YamlStructuredConfigProperties::toMap).collect(toList()))); + key, value.stream().map(YamlDeclarativeConfigProperties::toMap).collect(toList()))); mapEntries.forEach((key, value) -> result.put(key, value.toMap())); return Collections.unmodifiableMap(result); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactoryTest.java index 59dd61c03cf..2b3bca05212 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AttributeListFactoryTest.java @@ -10,8 +10,8 @@ import static org.mockito.Mockito.mock; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel; import java.util.Arrays; import java.util.Collections; @@ -31,7 +31,7 @@ void create_InvalidAttributes(List model, String expect () -> AttributeListFactory.getInstance() .create(model, mock(SpiHelper.class), Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessageContaining(expectedMessage); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigurationCreateTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationCreateTest.java similarity index 87% rename from sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigurationCreateTest.java rename to sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationCreateTest.java index d47ae14eb9a..45c2137b66a 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigurationCreateTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationCreateTest.java @@ -12,8 +12,8 @@ import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; import io.github.netmikey.logunit.api.LogCapturer; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.internal.testing.CleanupExtension; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -28,7 +28,7 @@ import org.junit.jupiter.api.io.TempDir; import org.slf4j.event.Level; -class FileConfigurationCreateTest { +class DeclarativeConfigurationCreateTest { @RegisterExtension static final SelfSignedCertificateExtension serverTls = new SelfSignedCertificateExtension(); @@ -40,12 +40,12 @@ class FileConfigurationCreateTest { @RegisterExtension LogCapturer logCapturer = - LogCapturer.create().captureForLogger(FileConfiguration.class.getName(), Level.TRACE); + LogCapturer.create().captureForLogger(DeclarativeConfiguration.class.getName(), Level.TRACE); /** * Verify each example in open-telemetry/opentelemetry-configuration/examples - * can pass {@link FileConfiguration#parseAndCreate(InputStream)}. + * can pass {@link DeclarativeConfiguration#parseAndCreate(InputStream)}. */ @Test void parseAndCreate_Examples(@TempDir Path tempDir) @@ -86,12 +86,15 @@ void parseAndCreate_Examples(@TempDir Path tempDir) "client_key: .*\n", "client_key: " + clientKeyPath + System.lineSeparator()) .replaceAll( "client_certificate: .*\n", - "client_certificate: " + clientCertificatePath + System.lineSeparator()); + "client_certificate: " + clientCertificatePath + System.lineSeparator()) + // TODO: remove once updated ComponentProvider SPI contract implemented in + // https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator + .replaceAll("xray,", ""); InputStream is = new ByteArrayInputStream(rewrittenExampleContent.getBytes(StandardCharsets.UTF_8)); // Verify that file can be parsed and interpreted without error - assertThatCode(() -> cleanup.addCloseable(FileConfiguration.parseAndCreate(is))) + assertThatCode(() -> cleanup.addCloseable(DeclarativeConfiguration.parseAndCreate(is))) .as("Example file: " + example.getName()) .doesNotThrowAnyException(); } @@ -115,9 +118,9 @@ void parseAndCreate_Exception_CleansUpPartials() { assertThatThrownBy( () -> - FileConfiguration.parseAndCreate( + DeclarativeConfiguration.parseAndCreate( new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)))) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.logs.export.LogRecordExporter with name \"foo\"."); logCapturer.assertContains( diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigurationParseTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java similarity index 98% rename from sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigurationParseTest.java rename to sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java index 81aa6f4487e..dc27e26d4dc 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfigurationParseTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java @@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AggregationModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AlwaysOffModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AlwaysOnModel; @@ -76,15 +76,15 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -class FileConfigurationParseTest { +class DeclarativeConfigurationParseTest { @Test void parse_BadInputStream() { assertThatThrownBy( () -> - FileConfiguration.parseAndCreate( + DeclarativeConfiguration.parseAndCreate( new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8)))) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("Unable to parse configuration input stream"); } @@ -446,7 +446,7 @@ void parse_KitchenSinkExampleFile() throws IOException { try (FileInputStream configExampleFile = new FileInputStream(System.getenv("CONFIG_EXAMPLE_DIR") + "/kitchen-sink.yaml")) { - OpenTelemetryConfigurationModel config = FileConfiguration.parse(configExampleFile); + OpenTelemetryConfigurationModel config = DeclarativeConfiguration.parse(configExampleFile); // General config assertThat(config.getFileFormat()).isEqualTo("0.1"); @@ -499,7 +499,7 @@ void parse_nullValuesParsedToEmptyObjects() { + " aggregation:\n" + " drop: {}\n"; OpenTelemetryConfigurationModel objectPlaceholderModel = - FileConfiguration.parse( + DeclarativeConfiguration.parse( new ByteArrayInputStream(objectPlaceholderString.getBytes(StandardCharsets.UTF_8))); String noOjbectPlaceholderString = @@ -517,7 +517,7 @@ void parse_nullValuesParsedToEmptyObjects() { + " aggregation:\n" + " drop:\n"; OpenTelemetryConfigurationModel noObjectPlaceholderModel = - FileConfiguration.parse( + DeclarativeConfiguration.parse( new ByteArrayInputStream(noOjbectPlaceholderString.getBytes(StandardCharsets.UTF_8))); SpanExporterModel exporter = @@ -551,7 +551,8 @@ void parse_nullBoxedPrimitivesParsedToNull() { + " ratio:\n"; // Double OpenTelemetryConfigurationModel model = - FileConfiguration.parse(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))); + DeclarativeConfiguration.parse( + new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))); assertThat(model.getFileFormat()).isNull(); assertThat(model.getDisabled()).isNull(); @@ -573,7 +574,7 @@ void parse_nullBoxedPrimitivesParsedToNull() { @MethodSource("coreSchemaValuesArgs") void coreSchemaValues(String rawYaml, Object expectedYamlResult) { Object yaml = - FileConfiguration.loadYaml( + DeclarativeConfiguration.loadYaml( new ByteArrayInputStream(rawYaml.getBytes(StandardCharsets.UTF_8)), Collections.emptyMap()); assertThat(yaml).isEqualTo(expectedYamlResult); @@ -601,7 +602,7 @@ void envSubstituteAndLoadYaml(String rawYaml, Object expectedYamlResult) { environmentVariables.put("HEX", "0xdeadbeef"); Object yaml = - FileConfiguration.loadYaml( + DeclarativeConfiguration.loadYaml( new ByteArrayInputStream(rawYaml.getBytes(StandardCharsets.UTF_8)), environmentVariables); assertThat(yaml).isEqualTo(expectedYamlResult); @@ -686,7 +687,7 @@ void read_WithEnvironmentVariables() { Map envVars = new HashMap<>(); envVars.put("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector:4317"); OpenTelemetryConfigurationModel model = - FileConfiguration.parse( + DeclarativeConfiguration.parse( new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)), envVars); assertThat(model) .isEqualTo( diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactoryTest.java index fd9a2640708..3f3192e5853 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/InstrumentSelectorFactoryTest.java @@ -9,8 +9,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SelectorModel; import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.InstrumentType; @@ -25,7 +25,7 @@ void create_Defaults() { () -> InstrumentSelectorFactory.getInstance() .create(new SelectorModel(), mock(SpiHelper.class), Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("Invalid selector"); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java index a9d9e4019c9..71bf980d410 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java @@ -14,12 +14,12 @@ import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.LogRecordExporterComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.NameStringValuePairModel; @@ -79,11 +79,11 @@ void create_OtlpDefaults() { assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper) .loadComponent(eq(LogRecordExporter.class), eq("otlp"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -148,14 +148,14 @@ void create_OtlpConfigured(@TempDir Path tempDir) assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper) .loadComponent(eq(LogRecordExporter.class), eq("otlp"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isEqualTo("http/protobuf"); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/logs"); - List headers = configProperties.getStructuredList("headers"); + List headers = configProperties.getStructuredList("headers"); assertThat(headers) .isNotNull() .satisfiesExactly( @@ -188,7 +188,7 @@ void create_SpiExporter_Unknown() { "unknown_key", ImmutableMap.of("key1", "value1")), spiHelper, new ArrayList<>())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.logs.export.LogRecordExporter with name \"unknown_key\"."); cleanup.addCloseables(closeables); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java index 3f3adb75066..1c70a225d7b 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java @@ -9,10 +9,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableMap; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.LogRecordProcessorComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchLogRecordProcessorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel; @@ -44,7 +44,7 @@ void create_BatchNullExporter() { new LogRecordProcessorModel().withBatch(new BatchLogRecordProcessorModel()), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("batch log record processor exporter is required but is null"); } @@ -112,7 +112,7 @@ void create_SimpleNullExporter() { .withSimple(new SimpleLogRecordProcessorModel()), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("simple log record processor exporter is required but is null"); } @@ -150,7 +150,7 @@ void create_SpiProcessor_Unknown() { "unknown_key", ImmutableMap.of("key1", "value1")), spiHelper, new ArrayList<>())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.logs.LogRecordProcessor with name \"unknown_key\"."); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java index 4f8b47f2e0c..6049e8a0dfb 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java @@ -14,13 +14,13 @@ import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.LoggingMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.MetricExporterComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ConsoleModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.NameStringValuePairModel; @@ -81,10 +81,10 @@ void create_OtlpDefaults() { assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper).loadComponent(eq(MetricExporter.class), eq("otlp"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -159,13 +159,13 @@ void create_OtlpConfigured(@TempDir Path tempDir) assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper).loadComponent(eq(MetricExporter.class), eq("otlp"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isEqualTo("http/protobuf"); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/metrics"); - List headers = configProperties.getStructuredList("headers"); + List headers = configProperties.getStructuredList("headers"); assertThat(headers) .isNotNull() .satisfiesExactly( @@ -220,7 +220,7 @@ void create_SpiExporter_Unknown() { "unknown_key", ImmutableMap.of("key1", "value1")), spiHelper, new ArrayList<>())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.metrics.export.MetricExporter with name \"unknown_key\"."); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java index cde7a9db49b..101f00ee0f9 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java @@ -11,11 +11,11 @@ import static org.mockito.Mockito.verify; import io.github.netmikey.logunit.api.LogCapturer; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; import io.opentelemetry.exporter.prometheus.PrometheusHttpServer; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.MetricReaderModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpMetricModel; @@ -40,7 +40,7 @@ class MetricReaderFactoryTest { @RegisterExtension LogCapturer logCapturer = - LogCapturer.create().captureForLogger(FileConfiguration.class.getName()); + LogCapturer.create().captureForLogger(DeclarativeConfiguration.class.getName()); private SpiHelper spiHelper = SpiHelper.create(MetricReaderFactoryTest.class.getClassLoader()); @@ -53,7 +53,7 @@ void create_PeriodicNullExporter() { new MetricReaderModel().withPeriodic(new PeriodicMetricReaderModel()), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("periodic metric reader exporter is required but is null"); } @@ -179,7 +179,7 @@ void create_InvalidPullReader() { new MetricReaderModel().withPull(new PullMetricReaderModel()), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("pull metric reader exporter is required but is null"); assertThatThrownBy( @@ -192,7 +192,7 @@ void create_InvalidPullReader() { .withExporter(new PullMetricExporterModel())), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("prometheus is the only currently supported pull reader"); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java index 0284a16bac4..953f2adc0a0 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java @@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.context.propagation.TextMapPropagator; @@ -22,7 +23,6 @@ import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AlwaysOnModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchLogRecordProcessorModel; @@ -82,7 +82,7 @@ void create_InvalidFileFormat() { () -> OpenTelemetryConfigurationFactory.getInstance() .create(testCase, spiHelper, closeables)) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("Unsupported file format. Supported formats include: 0.1"); cleanup.addCloseables(closeables); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactoryTest.java index 363bb301975..f57073d5246 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactoryTest.java @@ -9,10 +9,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableMap; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.SamplerComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AlwaysOffModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AlwaysOnModel; @@ -140,7 +140,7 @@ void create_SpiExporter_Unknown() { "unknown_key", ImmutableMap.of("key1", "value1")), spiHelper, new ArrayList<>())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.trace.samplers.Sampler with name \"unknown_key\"."); cleanup.addCloseables(closeables); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java index a6edf4039f1..88e3e4cd2dc 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java @@ -14,14 +14,14 @@ import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.SpanExporterComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ConsoleModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.NameStringValuePairModel; @@ -79,10 +79,10 @@ void create_OtlpDefaults() { assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper).loadComponent(eq(SpanExporter.class), eq("otlp"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -147,13 +147,13 @@ void create_OtlpConfigured(@TempDir Path tempDir) assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper).loadComponent(eq(SpanExporter.class), eq("otlp"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isEqualTo("http/protobuf"); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/traces"); - List headers = configProperties.getStructuredList("headers"); + List headers = configProperties.getStructuredList("headers"); assertThat(headers) .isNotNull() .satisfiesExactly( @@ -214,10 +214,10 @@ void create_ZipkinDefaults() { assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper).loadComponent(eq(SpanExporter.class), eq("zipkin"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getLong("timeout")).isNull(); } @@ -249,10 +249,10 @@ void create_ZipkinConfigured() { assertThat(exporter.toString()).isEqualTo(expectedExporter.toString()); - ArgumentCaptor configCaptor = - ArgumentCaptor.forClass(StructuredConfigProperties.class); + ArgumentCaptor configCaptor = + ArgumentCaptor.forClass(DeclarativeConfigProperties.class); verify(spiHelper).loadComponent(eq(SpanExporter.class), eq("zipkin"), configCaptor.capture()); - StructuredConfigProperties configProperties = configCaptor.getValue(); + DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://zipkin:9411/v1/v2/spans"); assertThat(configProperties.getLong("timeout")).isEqualTo(15_000); } @@ -271,7 +271,7 @@ void create_SpiExporter_Unknown() { "unknown_key", ImmutableMap.of("key1", "value1")), spiHelper, new ArrayList<>())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.trace.export.SpanExporter with name \"unknown_key\"."); cleanup.addCloseables(closeables); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java index 98af1e81ddc..85eff1f22bb 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java @@ -9,10 +9,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableMap; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.SpanProcessorComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchSpanProcessorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpModel; @@ -44,7 +44,7 @@ void create_BatchNullExporter() { new SpanProcessorModel().withBatch(new BatchSpanProcessorModel()), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("batch span processor exporter is required but is null"); } @@ -111,7 +111,7 @@ void create_SimpleNullExporter() { new SpanProcessorModel().withSimple(new SimpleSpanProcessorModel()), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("simple span processor exporter is required but is null"); } @@ -149,7 +149,7 @@ void create_SpiProcessor_Unknown() { "unknown_key", ImmutableMap.of("key1", "value1")), spiHelper, new ArrayList<>())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.sdk.trace.SpanProcessor with name \"unknown_key\"."); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java index d2a1d5d242d..17d21a7f364 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactoryTest.java @@ -9,13 +9,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; +import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.extension.trace.propagation.B3Propagator; import io.opentelemetry.extension.trace.propagation.JaegerPropagator; import io.opentelemetry.extension.trace.propagation.OtTracePropagator; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.TextMapPropagatorComponentProvider; import java.util.ArrayList; import java.util.Arrays; @@ -65,7 +65,7 @@ void create_NoneAndOther() { () -> TextMapPropagatorFactory.getInstance() .create(Arrays.asList("none", "foo"), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage("propagators contains \"none\" along with other propagators"); } @@ -75,7 +75,7 @@ void create_SpiPropagator_Unknown() { () -> TextMapPropagatorFactory.getInstance() .create(Collections.singletonList("foo"), spiHelper, Collections.emptyList())) - .isInstanceOf(ConfigurationException.class) + .isInstanceOf(DeclarativeConfigException.class) .hasMessage( "No component provider detected for io.opentelemetry.context.propagation.TextMapPropagator with name \"foo\"."); } @@ -91,7 +91,7 @@ void create_SpiPropagator_Valid() { testTextMapPropagator -> assertThat(testTextMapPropagator.config) .isInstanceOfSatisfying( - YamlStructuredConfigProperties.class, + YamlDeclarativeConfigProperties.class, config -> assertThat(config.getPropertyKeys()).isEmpty())); } } 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/YamlDeclarativeConfigPropertiesTest.java similarity index 88% rename from sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigPropertiesTest.java rename to sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigPropertiesTest.java index 757331934bf..2ec01806f83 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/YamlDeclarativeConfigPropertiesTest.java @@ -5,11 +5,11 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig; -import static io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties.empty; +import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; @@ -19,7 +19,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class YamlStructuredConfigPropertiesTest { +class YamlDeclarativeConfigPropertiesTest { private static final String extendedSchema = "file_format: \"0.1\"\n" @@ -56,23 +56,23 @@ class YamlStructuredConfigPropertiesTest { + " - str_key1: str_value1\n" + " int_key1: 2"; - private StructuredConfigProperties structuredConfigProps; + private DeclarativeConfigProperties structuredConfigProps; @BeforeEach void setup() { OpenTelemetryConfigurationModel configuration = - FileConfiguration.parse( + DeclarativeConfiguration.parse( new ByteArrayInputStream(extendedSchema.getBytes(StandardCharsets.UTF_8))); - structuredConfigProps = FileConfiguration.toConfigProperties(configuration); + structuredConfigProps = DeclarativeConfiguration.toConfigProperties(configuration); } @Test void configurationSchema() { // Validate can read file configuration schema properties assertThat(structuredConfigProps.getString("file_format")).isEqualTo("0.1"); - StructuredConfigProperties resourceProps = structuredConfigProps.getStructured("resource"); + DeclarativeConfigProperties resourceProps = structuredConfigProps.getStructured("resource"); assertThat(resourceProps).isNotNull(); - List resourceAttributesList = + List resourceAttributesList = resourceProps.getStructuredList("attributes"); assertThat(resourceAttributesList) .isNotNull() @@ -90,7 +90,7 @@ void additionalProperties() { // Validate can read properties not part of configuration schema // .other - StructuredConfigProperties otherProps = structuredConfigProps.getStructured("other"); + DeclarativeConfigProperties otherProps = structuredConfigProps.getStructured("other"); assertThat(otherProps).isNotNull(); assertThat(otherProps.getPropertyKeys()) .isEqualTo( @@ -135,14 +135,15 @@ void additionalProperties() { .isEqualTo(Collections.singletonList(true)); // .other.map_key - StructuredConfigProperties otherMapKeyProps = otherProps.getStructured("map_key"); + DeclarativeConfigProperties otherMapKeyProps = otherProps.getStructured("map_key"); assertThat(otherMapKeyProps).isNotNull(); assertThat(otherMapKeyProps.getPropertyKeys()) .isEqualTo(ImmutableSet.of("str_key1", "int_key1", "map_key1")); assertThat(otherMapKeyProps.getString("str_key1")).isEqualTo("str_value1"); assertThat(otherMapKeyProps.getInt("int_key1")).isEqualTo(2); // other.map_key.map_key1 - StructuredConfigProperties otherMapKeyMapKey1Props = otherMapKeyProps.getStructured("map_key1"); + DeclarativeConfigProperties otherMapKeyMapKey1Props = + otherMapKeyProps.getStructured("map_key1"); assertThat(otherMapKeyMapKey1Props).isNotNull(); assertThat(otherMapKeyMapKey1Props.getPropertyKeys()) .isEqualTo(ImmutableSet.of("str_key2", "int_key2")); @@ -150,22 +151,22 @@ void additionalProperties() { assertThat(otherMapKeyMapKey1Props.getInt("int_key2")).isEqualTo(3); // .other.list_key - List listKey = otherProps.getStructuredList("list_key"); + List listKey = otherProps.getStructuredList("list_key"); assertThat(listKey).hasSize(2); - StructuredConfigProperties listKeyProps1 = listKey.get(0); + DeclarativeConfigProperties listKeyProps1 = listKey.get(0); assertThat(listKeyProps1.getPropertyKeys()) .isEqualTo(ImmutableSet.of("str_key1", "int_key1", "map_key1")); assertThat(listKeyProps1.getString("str_key1")).isEqualTo("str_value1"); assertThat(listKeyProps1.getInt("int_key1")).isEqualTo(2); // .other.list_key[0] - StructuredConfigProperties listKeyProps1MapKeyProps = listKeyProps1.getStructured("map_key1"); + DeclarativeConfigProperties listKeyProps1MapKeyProps = listKeyProps1.getStructured("map_key1"); assertThat(listKeyProps1MapKeyProps).isNotNull(); assertThat(listKeyProps1MapKeyProps.getPropertyKeys()) .isEqualTo(ImmutableSet.of("str_key2", "int_key2")); assertThat(listKeyProps1MapKeyProps.getString("str_key2")).isEqualTo("str_value2"); assertThat(listKeyProps1MapKeyProps.getInt("int_key2")).isEqualTo(3); // .other.list_key[1] - StructuredConfigProperties listKeyProps2 = listKey.get(1); + DeclarativeConfigProperties listKeyProps2 = listKey.get(1); assertThat(listKeyProps2.getPropertyKeys()).isEqualTo(ImmutableSet.of("str_key1", "int_key1")); assertThat(listKeyProps2.getString("str_key1")).isEqualTo("str_value1"); assertThat(listKeyProps2.getInt("int_key1")).isEqualTo(2); @@ -213,7 +214,7 @@ void missingKeys() { @Test void wrongType() { - StructuredConfigProperties otherProps = structuredConfigProps.getStructured("other"); + DeclarativeConfigProperties otherProps = structuredConfigProps.getStructured("other"); assertThat(otherProps).isNotNull(); assertThat(otherProps.getString("int_key")).isNull(); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java index 2f2d6f56c7c..f21c1d1bf09 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java @@ -5,8 +5,8 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.logs.export.LogRecordExporter; @@ -24,15 +24,15 @@ public String getName() { } @Override - public LogRecordExporter create(StructuredConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config) { return new TestLogRecordExporter(config); } public static class TestLogRecordExporter implements LogRecordExporter { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestLogRecordExporter(StructuredConfigProperties config) { + private TestLogRecordExporter(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java index 581f2726154..a44cd939c74 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.ReadWriteLogRecord; @@ -24,15 +24,15 @@ public String getName() { } @Override - public LogRecordProcessor create(StructuredConfigProperties config) { + public LogRecordProcessor create(DeclarativeConfigProperties config) { return new TestLogRecordProcessor(config); } public static class TestLogRecordProcessor implements LogRecordProcessor { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestLogRecordProcessor(StructuredConfigProperties config) { + private TestLogRecordProcessor(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java index b0c46a8be92..80ea6b556ce 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java @@ -5,8 +5,8 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.metrics.InstrumentType; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; @@ -27,15 +27,15 @@ public String getName() { } @Override - public MetricExporter create(StructuredConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config) { return new TestMetricExporter(config); } public static class TestMetricExporter implements MetricExporter { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestMetricExporter(StructuredConfigProperties config) { + private TestMetricExporter(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java index 13b0e86c05a..0ec06894896 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java @@ -5,8 +5,8 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.resources.Resource; public class ResourceComponentProvider implements ComponentProvider { @@ -21,7 +21,7 @@ public String getName() { } @Override - public Resource create(StructuredConfigProperties config) { + public Resource create(DeclarativeConfigProperties config) { return Resource.builder().put("shape", "square").put("color", "red").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedFirstComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedFirstComponentProvider.java index f2f41e5b955..181c7b469c8 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedFirstComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedFirstComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.resources.Resource; public class ResourceOrderedFirstComponentProvider implements ComponentProvider, Ordered { @@ -22,7 +22,7 @@ public String getName() { } @Override - public Resource create(StructuredConfigProperties config) { + public Resource create(DeclarativeConfigProperties config) { return Resource.builder().put("order", "first").build(); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedSecondComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedSecondComponentProvider.java index 00017b2b7d4..5cbb5e299e4 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedSecondComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceOrderedSecondComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.resources.Resource; public class ResourceOrderedSecondComponentProvider @@ -23,7 +23,7 @@ public String getName() { } @Override - public Resource create(StructuredConfigProperties config) { + public Resource create(DeclarativeConfigProperties config) { return Resource.builder().put("order", "second").build(); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java index 2d4c983e4d7..3264dd91fc7 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java @@ -6,10 +6,10 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.trace.data.LinkData; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.SamplingResult; @@ -27,15 +27,15 @@ public String getName() { } @Override - public Sampler create(StructuredConfigProperties config) { + public Sampler create(DeclarativeConfigProperties config) { return new TestSampler(config); } public static class TestSampler implements Sampler { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestSampler(StructuredConfigProperties config) { + private TestSampler(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java index f387454f0fd..ddaca3ca4b9 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java @@ -5,8 +5,8 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; @@ -24,15 +24,15 @@ public String getName() { } @Override - public SpanExporter create(StructuredConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config) { return new TestSpanExporter(config); } public static class TestSpanExporter implements SpanExporter { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestSpanExporter(StructuredConfigProperties config) { + private TestSpanExporter(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java index 7bfe0936cd9..3a1ddf9b13a 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.trace.ReadWriteSpan; import io.opentelemetry.sdk.trace.ReadableSpan; @@ -25,15 +25,15 @@ public String getName() { } @Override - public SpanProcessor create(StructuredConfigProperties config) { + public SpanProcessor create(DeclarativeConfigProperties config) { return new TestSpanProcessor(config); } public static class TestSpanProcessor implements SpanProcessor { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestSpanProcessor(StructuredConfigProperties config) { + private TestSpanProcessor(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java index a3005beba4b..0ab454da8ad 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java @@ -5,12 +5,12 @@ package io.opentelemetry.sdk.extension.incubator.fileconfig.component; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; import java.util.Collection; import java.util.Collections; import javax.annotation.Nullable; @@ -27,15 +27,15 @@ public String getName() { } @Override - public TextMapPropagator create(StructuredConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return new TestTextMapPropagator(config); } public static class TestTextMapPropagator implements TextMapPropagator { - public final StructuredConfigProperties config; + public final DeclarativeConfigProperties config; - private TestTextMapPropagator(StructuredConfigProperties config) { + private TestTextMapPropagator(DeclarativeConfigProperties config) { this.config = config; } diff --git a/sdk-extensions/jaeger-remote-sampler/build.gradle.kts b/sdk-extensions/jaeger-remote-sampler/build.gradle.kts index ac250eef3d1..32b51d6065d 100644 --- a/sdk-extensions/jaeger-remote-sampler/build.gradle.kts +++ b/sdk-extensions/jaeger-remote-sampler/build.gradle.kts @@ -12,6 +12,7 @@ otelJava.moduleName.set("io.opentelemetry.sdk.extension.trace.jaeger") dependencies { api(project(":sdk:all")) + compileOnly(project(":api:incubator")) compileOnly(project(":sdk-extensions:autoconfigure")) compileOnly(project(":sdk-extensions:incubator")) diff --git a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java index 9ce99c908b2..fd89f42cae9 100644 --- a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java +++ b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java @@ -5,9 +5,9 @@ package io.opentelemetry.sdk.extension.trace.jaeger.sampler.internal; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; -import io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfiguration; +import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration; import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSampler; import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSamplerBuilder; import io.opentelemetry.sdk.trace.samplers.Sampler; @@ -31,7 +31,7 @@ public String getName() { } @Override - public Sampler create(StructuredConfigProperties config) { + public Sampler create(DeclarativeConfigProperties config) { JaegerRemoteSamplerBuilder builder = JaegerRemoteSampler.builder(); // Optional configuration @@ -43,9 +43,9 @@ public Sampler create(StructuredConfigProperties config) { if (pollingIntervalMs != null) { builder.setPollingInterval(Duration.ofMillis(pollingIntervalMs)); } - StructuredConfigProperties initialSamplerModel = config.getStructured("initial_sampler"); + DeclarativeConfigProperties initialSamplerModel = config.getStructured("initial_sampler"); if (initialSamplerModel != null) { - Sampler initialSampler = FileConfiguration.createSampler(initialSamplerModel); + Sampler initialSampler = DeclarativeConfiguration.createSampler(initialSamplerModel); builder.setInitialSampler(initialSampler); }