-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add contrib-facing helpers to the declarative config bridge #19220
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 18 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
352c7f0
feat: Replace DeclarativeConfigPropertiesBridge with ConfigProperties…
aviralgarg05 4455375
fix: Resolve build and formatting issues
aviralgarg05 ceefeb5
Suppress deprecation warnings for backward compatibility
aviralgarg05 c720a10
Merge upstream/main into fix/issue-15811
aviralgarg05 fa9133d
Address PR feedback: preserve special mappings and track 3.0 removal
aviralgarg05 8270514
Merge remote-tracking branch 'upstream/main' into fix/issue-15811
trask 8213aed
Address remaining PR review feedback
aviralgarg05 b432212
Merge branch 'main' into fix/issue-15811
aviralgarg05 d02c1de
Merge remote-tracking branch 'upstream/main' into fix/issue-15811
trask 74b8b25
Address remaining PR review feedback
aviralgarg05 346ed3d
Merge remote-tracking branch 'upstream/main' into fix/issue-15811
aviralgarg05 151b681
Merge remote-tracking branch 'origin/fix/issue-15811' into fix/issue-…
aviralgarg05 aaa02b3
fix: use Java-compatible empty map in config provider test
aviralgarg05 c1683da
fix: satisfy spotless for config provider test
aviralgarg05 7a34a99
configurable access path
zeitlinger 15ce857
Merge remote-tracking branch 'origin/main' into cp-bridge-for-distros
zeitlinger 7e7938f
add DeclarativeConfigPropertiesDurationUtil
zeitlinger 2bc1684
Add contrib-facing declarative bridge helpers
zeitlinger 640ea3c
cleanup
zeitlinger c825e84
Fix component provider example in bridge README
zeitlinger 55f9e56
Update declarative-config-bridge/src/main/java/io/opentelemetry/instr…
zeitlinger 05d1972
Fix declarative config bridge review findings
trask 19e9f58
Rename declarative duration helper
trask 264b8bd
Simplify declarative config bridge API
trask e8b277f
Scope deprecated API suppression
trask 1aabda1
Address review comment from copilot-pull-request-reviewer: isolate co…
trask 174e659
Address review comment from copilot-pull-request-reviewer: correct pr…
trask 10fda27
Address review comment from copilot-pull-request-reviewer: narrow hel…
trask 5920f40
Address review comment from copilot-pull-request-reviewer: document b…
trask 8c61aa3
Merge remote-tracking branch 'upstream/main' into cp-bridge-for-contrib
trask eae11a0
spotless
trask 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| package io.opentelemetry.instrumentation.config.bridge; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
| import static java.util.Collections.emptyMap; | ||
| import static java.util.Collections.emptySet; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
|
|
@@ -28,6 +29,8 @@ | |
| final class ConfigPropertiesBackedDeclarativeConfigProperties | ||
| implements DeclarativeConfigProperties { | ||
|
|
||
| static final String DEFAULT_ACCESS_ROOT = "java."; | ||
| static final String DEFAULT_RESULT_PREFIX = "otel.instrumentation."; | ||
| private static final String JAVA_COMMON_SERVICE_PEER_MAPPING = "java.common.service_peer_mapping"; | ||
|
|
||
| private static final Map<String, String> SPECIAL_MAPPINGS; | ||
|
|
@@ -94,16 +97,44 @@ final class ConfigPropertiesBackedDeclarativeConfigProperties | |
|
|
||
| private final ConfigProperties configProperties; | ||
| private final List<String> path; | ||
| private final Map<String, String> mappings; | ||
|
Member
Author
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. not sure if it makes sense to extract an object that contains all of those properties (all but |
||
| private final String accessRoot; | ||
| private final String resultPrefix; | ||
|
|
||
| static DeclarativeConfigProperties createInstrumentationConfig( | ||
| ConfigProperties configProperties) { | ||
| return new ConfigPropertiesBackedDeclarativeConfigProperties(configProperties, emptyList()); | ||
| return createInstrumentationConfig( | ||
| configProperties, emptyMap(), DEFAULT_ACCESS_ROOT, DEFAULT_RESULT_PREFIX); | ||
| } | ||
|
|
||
| static DeclarativeConfigProperties createInstrumentationConfig( | ||
| ConfigProperties configProperties, | ||
| Map<String, String> mappings, | ||
| String accessRoot, | ||
| String resultPrefix) { | ||
| for (String mapping : mappings.keySet()) { | ||
| if (SPECIAL_MAPPINGS.containsKey(mapping)) { | ||
| throw new IllegalArgumentException( | ||
| "Custom mapping must not override built-in mapping: " + mapping); | ||
| } | ||
| } | ||
| Map<String, String> mergedMappings = new HashMap<>(SPECIAL_MAPPINGS); | ||
| mergedMappings.putAll(mappings); | ||
| return new ConfigPropertiesBackedDeclarativeConfigProperties( | ||
| configProperties, emptyList(), mergedMappings, accessRoot, resultPrefix); | ||
| } | ||
|
|
||
| private ConfigPropertiesBackedDeclarativeConfigProperties( | ||
| ConfigProperties configProperties, List<String> path) { | ||
| ConfigProperties configProperties, | ||
| List<String> path, | ||
| Map<String, String> mappings, | ||
| String accessRoot, | ||
| String resultPrefix) { | ||
| this.configProperties = configProperties; | ||
| this.path = path; | ||
| this.mappings = mappings; | ||
| this.accessRoot = accessRoot; | ||
| this.resultPrefix = resultPrefix; | ||
| } | ||
|
|
||
| @Nullable | ||
|
|
@@ -162,7 +193,8 @@ public Double getDouble(String name) { | |
| public DeclarativeConfigProperties getStructured(String name) { | ||
| List<String> newPath = new ArrayList<>(path); | ||
| newPath.add(name); | ||
| return new ConfigPropertiesBackedDeclarativeConfigProperties(configProperties, newPath); | ||
| return new ConfigPropertiesBackedDeclarativeConfigProperties( | ||
| configProperties, newPath, mappings, accessRoot, resultPrefix); | ||
| } | ||
|
|
||
| @Nullable | ||
|
|
@@ -208,17 +240,16 @@ private String resolvePropertyKey(String name) { | |
| String fullPath = pathWithName(name); | ||
|
|
||
| // Check explicit property mappings first | ||
| String mappedKey = SPECIAL_MAPPINGS.get(fullPath); | ||
| String mappedKey = mappings.get(fullPath); | ||
| if (mappedKey != null) { | ||
| return mappedKey; | ||
| } | ||
|
|
||
| if (!fullPath.startsWith("java.")) { | ||
| if (!accessRoot.isEmpty() && !fullPath.startsWith(accessRoot)) { | ||
| return ""; | ||
| } | ||
|
|
||
| // Remove "java." prefix and translate the remaining path | ||
| String[] segments = fullPath.substring(5).split("\\."); | ||
| String[] segments = fullPath.substring(accessRoot.length()).split("\\."); | ||
| StringBuilder translatedPath = new StringBuilder(); | ||
|
|
||
| for (int i = 0; i < segments.length; i++) { | ||
|
|
@@ -228,7 +259,7 @@ private String resolvePropertyKey(String name) { | |
| translatedPath.append(translateName(segments[i])); | ||
|
trask marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return "otel.instrumentation." + translatedPath; | ||
| return resultPrefix + translatedPath; | ||
| } | ||
|
|
||
| private String pathWithName(String name) { | ||
|
|
||
53 changes: 53 additions & 0 deletions
53
.../opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesDurationUtil.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,53 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.config.bridge; | ||
|
|
||
| import static java.util.Collections.singletonMap; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; | ||
| import java.time.Duration; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Helpers for reading duration values from {@link DeclarativeConfigProperties}. | ||
| * | ||
| * <p>When the config is backed by flat {@link | ||
| * io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties}, duration strings such as {@code 42ms} | ||
| * are supported by delegating to the SDK's standard duration parser. | ||
| * | ||
| * <p>For other declarative-config implementations, this utility expects duration values to already | ||
| * be normalized to integer milliseconds, which means string durations in declarative YAML are not | ||
| * accepted. | ||
| */ | ||
| public final class DeclarativeConfigPropertiesDurationUtil { | ||
|
|
||
| private DeclarativeConfigPropertiesDurationUtil() {} | ||
|
|
||
| /** | ||
| * Reads a duration from declarative config. | ||
| * | ||
| * <p>String duration values are only supported when {@code properties} is a {@link | ||
| * ConfigPropertiesBackedDeclarativeConfigProperties}. Other implementations must provide integer | ||
| * milliseconds for the same key. | ||
| */ | ||
| @Nullable | ||
| public static Duration parseDuration(DeclarativeConfigProperties properties, String key) { | ||
| if (properties instanceof ConfigPropertiesBackedDeclarativeConfigProperties) { | ||
| String rawValue = properties.getString(key); | ||
| if (rawValue == null || rawValue.isEmpty()) { | ||
| return null; | ||
| } | ||
| return DefaultConfigProperties.createFromMap(singletonMap(key, rawValue)).getDuration(key); | ||
| } | ||
|
|
||
| Long rawLongValue = properties.getLong(key); | ||
| if (rawLongValue == null) { | ||
| return null; | ||
| } | ||
| return Duration.ofMillis(rawLongValue); | ||
| } | ||
| } |
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.