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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Declarative Configuration Jackson 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`. | ||
|
|
||
| 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`. |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to include the jackson major version number in the module name. I.e. declarative-config-jackson2. We learned the hard was with okhttp sender that people have a real problem with major version updates with these kind of load bearing dependencies. Embedding the major version gives us flexibility to maintain two versions at the same time to keep everyone happy. Can of course start without the version in the name and rename to declarative-config-jackson3 if/when needed, but its a nice visual queue to start with. Also put the major version in the package name, i.e. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||
| plugins { | ||||||||
| id("otel.java-conventions") | ||||||||
| id("otel.publish-conventions") | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| description = "OpenTelemetry SDK Declarative Config Jackson Mapper" | ||||||||
| otelJava.moduleName.set("io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson") | ||||||||
| otelJava.requireSuppressWarningsExplanation.set(false) | ||||||||
| otelJava.osgiServiceLoaderProvides.set(listOf( | ||||||||
| "io.opentelemetry.sdk.autoconfigure.declarativeconfig.spi.DeclarativeConfigurationMapper", | ||||||||
| )) | ||||||||
|
|
||||||||
| dependencies { | ||||||||
| api(project(":sdk-extensions:declarative-config-spi")) | ||||||||
| implementation("com.fasterxml.jackson.core:jackson-databind") | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| otel.release=alpha |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson.internal; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import io.opentelemetry.sdk.autoconfigure.declarativeconfig.spi.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 int order() { | ||
| return Integer.MIN_VALUE; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T convert(Object value, Class<T> targetType) { | ||
| return JacksonModelMapper.MAPPER.convertValue(value, targetType); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Map<String, Object> toMap(Object value) { | ||
| return JacksonModelMapper.MAPPER.convertValue( | ||
| value, new TypeReference<Map<String, Object>>() {}); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.opentelemetry.sdk.autoconfigure.declarativeconfig.jackson.internal.JacksonDeclarativeConfigurationMapper |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey let's put these in sdk-extensions/autoconfigure-spi in the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| plugins { | ||
| id("otel.java-conventions") | ||
| id("otel.publish-conventions") | ||
| } | ||
|
|
||
| description = "OpenTelemetry SDK Declarative Config SPI" | ||
| otelJava.moduleName.set("io.opentelemetry.sdk.autoconfigure.declarativeconfig.spi") | ||
| otelJava.requireSuppressWarningsExplanation.set(false) | ||
|
|
||
| dependencies { | ||
| api(project(":sdk-extensions:autoconfigure-spi")) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| otel.release=alpha |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.declarativeconfig.spi; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.Ordered; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Converts parsed configuration values to declarative configuration models and generic maps. | ||
| * | ||
| * <p>Implementations are discovered with {@link java.util.ServiceLoader}. The implementation with | ||
| * the highest {@link #order()} is used. The Jackson 2 implementation is supplied by the {@code | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The typical pattern we use is:
|
||
| * opentelemetry-sdk-extension-declarative-config-jackson} runtime adapter, which is included by | ||
| * default with declarative config and can be excluded when using a custom mapper. Implementations | ||
| * must preserve the mapping behavior of the declarative configuration models, including extension | ||
| * properties and null values. | ||
| */ | ||
| public interface DeclarativeConfigurationMapper extends Ordered { | ||
|
|
||
| /** | ||
| * 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 | ||
| */ | ||
| <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 | ||
| */ | ||
| @Nullable | ||
| Map<String, Object> toMap(Object value); | ||
| } | ||
| 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.declarativeconfig.spi; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.Ordered; | ||
| import java.io.InputStream; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Parses a declarative configuration YAML stream into generic Java objects. | ||
| * | ||
| * <p>Implementations are discovered with {@link java.util.ServiceLoader}. The implementation with | ||
| * the highest {@link #order()} is used. The built-in parser has the lowest possible order and is | ||
| * used when no other implementation is registered. | ||
| * | ||
| * <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. | ||
| */ | ||
| public interface DeclarativeConfigurationYamlParser extends Ordered { | ||
|
|
||
| /** | ||
| * 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 | ||
| */ | ||
| Object parse( | ||
| InputStream configuration, | ||
| Map<String, String> environmentVariables, | ||
| Map<Object, Object> systemProperties); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for changelog entries. These are generated as part of release notes.