-
Notifications
You must be signed in to change notification settings - Fork 956
Introduce ConfigProvider API #6549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c5cdc1c
Introduce ConfigProvider API
jack-berg 6ec7a0a
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg a624c70
partially incorporate pr feedback
jack-berg e986018
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg 0389e1c
Rename to declarative configuration
jack-berg 64df541
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg b184a59
Simplify InstrumentationConfigUtil
jack-berg 81f601c
Cleanup, reduce dependencies to compileOnly
jack-berg 20de4ef
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg 08c2eec
Autoconfigure compileOnly dependency on api incubator
jack-berg 0a9791b
Otlp exporter compileOnly dependency on api incubator
jack-berg c2a3cf7
Typos
jack-berg 21315eb
Make InstrumentationConfigUtil#getOrNull public
jack-berg 4782b9f
PR feedback
jack-berg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ConfigProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| * | ||
| * <p>The name <i>Provider</i> is for consistency with other languages and it is <b>NOT</b> loaded | ||
| * using reflection. | ||
| * | ||
| * <p>See {@link InstrumentationConfigUtil} for convenience methods for extracting config from | ||
| * {@link ConfigProvider}. | ||
| */ | ||
| @ThreadSafe | ||
| public interface ConfigProvider { | ||
|
|
||
| /** | ||
| * Returns the {@link DeclarativeConfigProperties} corresponding to <a | ||
| * href="https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema/instrumentation.json">instrumentation | ||
| * config</a>, or {@code null} if unavailable. | ||
| * | ||
| * @return the instrumentation {@link DeclarativeConfigProperties} | ||
| */ | ||
| @Nullable | ||
| DeclarativeConfigProperties getInstrumentationConfig(); | ||
|
|
||
| /** Returns a no-op {@link ConfigProvider}. */ | ||
| static ConfigProvider noop() { | ||
| return () -> null; | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
...bator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
api/incubator/src/main/java/io/opentelemetry/api/incubator/config/GlobalConfigProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<ConfigProvider> 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. | ||
jack-berg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * @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() { | ||
jack-berg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| instance.set(ConfigProvider.noop()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.