Repository navigation
Make declarative config parsing and mapping pluggable #8983
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
jack-berg
merged 15 commits into
open-telemetry:main
from
ash-thakur-rh:features/fe-config-spi
Nov 13, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1b41300
feat: Make declarative config parsing and mapping pluggable
ash-thakur-rh a103e4d
feat: dependency fix based on tests run
ash-thakur-rh 93ffc5d
feat: few changes for better arch
ash-thakur-rh bf33c6f
feat: fixes as per suggestions
ash-thakur-rh 8fcb020
feat: update to move mapper from internal package
ash-thakur-rh fd8e4ac
feat: update to move mapper from internal package
ash-thakur-rh 657ee4a
feat: minor fixes
ash-thakur-rh cc4a52b
feat: apply same logic to parser autoconfigure
ash-thakur-rh 82dfaa7
Merge branch 'main' into features/fe-config-spi
ash-thakur-rh 957940c
feat: updates as per code review
ash-thakur-rh 77de82f
feat: updates for tests
ash-thakur-rh c2ebc56
feat: update readme doc
ash-thakur-rh a72d54f
Final tweaks
jack-berg f584b4a
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg f283bcd
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
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
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
43 changes: 43 additions & 0 deletions
43
.../java/io/opentelemetry/sdk/autoconfigure/spi/internal/DeclarativeConfigurationMapper.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,43 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.spi.internal; | ||
|
|
||
| import io.opentelemetry.api.config.DeclarativeConfigException; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Converts parsed configuration values to declarative configuration models and generic maps. | ||
| * | ||
| * <p>Implementations must preserve the models' mapping semantics, including extension properties | ||
| * and null values. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public interface DeclarativeConfigurationMapper { | ||
|
|
||
| /** | ||
| * Convert a value to an instance of {@code targetType}. | ||
| * | ||
| * @param value the value to convert | ||
| * @param targetType the target type | ||
| * @param <T> the target type | ||
| * @return the converted value | ||
| * @throws DeclarativeConfigException if the value cannot be converted to {@code targetType} | ||
| */ | ||
| <T> T convert(Object value, Class<T> targetType); | ||
|
|
||
| /** | ||
| * Convert a model or parsed configuration value to a map with string keys. | ||
| * | ||
| * @param value the value to convert | ||
| * @return the converted map, or null if the input value is null | ||
| * @throws DeclarativeConfigException if the value cannot be converted to a map | ||
| */ | ||
| @Nullable | ||
| Map<String, Object> toMap(Object value); | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
...a/io/opentelemetry/sdk/autoconfigure/spi/internal/DeclarativeConfigurationYamlParser.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,38 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.spi.internal; | ||
|
|
||
| import io.opentelemetry.api.config.DeclarativeConfigException; | ||
| import java.io.InputStream; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Parses a declarative configuration YAML stream into generic Java objects. | ||
| * | ||
| * <p>Implementations must apply environment variable and system property substitution according to | ||
| * the OpenTelemetry Configuration Data Model specification. Substitution is performed on scalar | ||
| * values, not mapping keys. For unquoted scalar values, substituted text must be parsed using the | ||
| * same YAML scalar rules as the original text. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public interface DeclarativeConfigurationYamlParser { | ||
|
|
||
| /** | ||
| * Parse a YAML stream. | ||
| * | ||
| * @param configuration the YAML input stream | ||
| * @param environmentVariables environment variables used for substitution | ||
| * @param systemProperties system properties used for substitution | ||
| * @return the parsed configuration | ||
| * @throws DeclarativeConfigException if the YAML cannot be parsed | ||
| */ | ||
| Object parse( | ||
| InputStream configuration, | ||
| Map<String, String> environmentVariables, | ||
| Map<Object, Object> systemProperties); | ||
| } |
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,9 @@ | ||
| # Declarative Configuration Jackson 2 Mapper | ||
|
|
||
| This extension provides a Jackson 2 implementation of the `DeclarativeConfigurationMapper` SPI. | ||
| It is included as a runtime dependency by `opentelemetry-sdk-extension-declarative-config` from | ||
| the `opentelemetry-sdk-extension-declarative-config-jackson2` artifact. | ||
|
|
||
| Projects using another mapper can exclude this artifact from the declarative-config dependency and | ||
| register their own `DeclarativeConfigurationMapper` provider. For example, a project using Jackson 3 | ||
| can implement the SPI with its Jackson 3 `ObjectMapper`. |
17 changes: 17 additions & 0 deletions
17
sdk-extensions/declarative-config-jackson2/build.gradle.kts
|
jack-berg marked this conversation as resolved.
Resolved
|
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,17 @@ | ||
| plugins { | ||
| id("otel.java-conventions") | ||
| id("otel.publish-conventions") | ||
|
jack-berg marked this conversation as resolved.
Resolved
|
||
| id("otel.animalsniffer-conventions") | ||
| } | ||
|
|
||
| description = "OpenTelemetry SDK Declarative Config Jackson 2 Mapper" | ||
| otelJava.moduleName.set("io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson2") | ||
| otelJava.requireSuppressWarningsExplanation.set(false) | ||
| otelJava.osgiServiceLoaderProvides.set(listOf( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.internal.DeclarativeConfigurationMapper", | ||
| )) | ||
|
|
||
| dependencies { | ||
| api(project(":sdk-extensions:autoconfigure-spi")) | ||
| implementation("com.fasterxml.jackson.core:jackson-databind") | ||
| } | ||
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 @@ | ||
| otel.release=alpha |
39 changes: 39 additions & 0 deletions
39
...oconfigure/declarativeconfig/jackson2/internal/JacksonDeclarativeConfigurationMapper.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,39 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson2.internal; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import io.opentelemetry.api.config.DeclarativeConfigException; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.DeclarativeConfigurationMapper; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
| * any time. | ||
| */ | ||
| public final class JacksonDeclarativeConfigurationMapper implements DeclarativeConfigurationMapper { | ||
|
|
||
| @Override | ||
| public <T> T convert(Object value, Class<T> targetType) { | ||
| try { | ||
| return JacksonModelMapper.MAPPER.convertValue(value, targetType); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new DeclarativeConfigException("Unable to convert value to " + targetType, e); | ||
| } | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Map<String, Object> toMap(Object value) { | ||
| try { | ||
| return JacksonModelMapper.MAPPER.convertValue( | ||
| value, new TypeReference<Map<String, Object>>() {}); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new DeclarativeConfigException("Unable to convert value to a map", e); | ||
| } | ||
| } | ||
| } |
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
1 change: 1 addition & 0 deletions
1
...F/services/io.opentelemetry.sdk.autoconfigure.spi.internal.DeclarativeConfigurationMapper
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 @@ | ||
| io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson2.internal.JacksonDeclarativeConfigurationMapper |
31 changes: 31 additions & 0 deletions
31
...figure/declarativeconfig/jackson2/internal/JacksonDeclarativeConfigurationMapperTest.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,31 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson2.internal; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import io.opentelemetry.api.config.DeclarativeConfigException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class JacksonDeclarativeConfigurationMapperTest { | ||
|
|
||
| private final JacksonDeclarativeConfigurationMapper mapper = | ||
| new JacksonDeclarativeConfigurationMapper(); | ||
|
|
||
| @Test | ||
| void convertWrapsJacksonException() { | ||
| assertThatThrownBy(() -> mapper.convert("not-an-integer", Integer.class)) | ||
| .isInstanceOf(DeclarativeConfigException.class) | ||
| .hasCauseInstanceOf(IllegalArgumentException.class); | ||
| } | ||
|
|
||
| @Test | ||
| void toMapWrapsJacksonException() { | ||
| assertThatThrownBy(() -> mapper.toMap(42)) | ||
| .isInstanceOf(DeclarativeConfigException.class) | ||
| .hasCauseInstanceOf(IllegalArgumentException.class); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
sdk-extensions/declarative-config-snakeyaml-engine2/README.md
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,9 @@ | ||
| # SnakeYAML Engine 2 Declarative Configuration Parser | ||
|
|
||
| This module provides the default `DeclarativeConfigurationYamlParser` implementation using | ||
| SnakeYAML Engine 2. It is included as a runtime dependency by | ||
| `opentelemetry-sdk-extension-declarative-config`. | ||
|
|
||
| Applications that provide a custom YAML parser can exclude this module from the declarative config | ||
| dependency and register their parser with `ServiceLoader`. If neither this adapter nor another | ||
| parser provider is present, YAML parsing fails with a `DeclarativeConfigException`. |
17 changes: 17 additions & 0 deletions
17
sdk-extensions/declarative-config-snakeyaml-engine2/build.gradle.kts
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,17 @@ | ||
| plugins { | ||
| id("otel.java-conventions") | ||
| id("otel.publish-conventions") | ||
| id("otel.animalsniffer-conventions") | ||
| } | ||
|
|
||
| description = "OpenTelemetry SDK Declarative Config SnakeYAML Engine 2 Parser" | ||
| otelJava.moduleName.set("io.opentelemetry.sdk.autoconfigure.declarativeconfig.snakeyamlengine2") | ||
| otelJava.requireSuppressWarningsExplanation.set(false) | ||
| otelJava.osgiServiceLoaderProvides.set(listOf( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.internal.DeclarativeConfigurationYamlParser", | ||
| )) | ||
|
|
||
| dependencies { | ||
| api(project(":sdk-extensions:autoconfigure-spi")) | ||
| implementation("org.snakeyaml:snakeyaml-engine") | ||
| } |
1 change: 1 addition & 0 deletions
1
sdk-extensions/declarative-config-snakeyaml-engine2/gradle.properties
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 @@ | ||
| otel.release=alpha |
Oops, something went wrong.
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.