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