Skip to content
Merged
Show file tree
Hide file tree
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 Jan 11, 2026
4455375
fix: Resolve build and formatting issues
aviralgarg05 Jan 11, 2026
ceefeb5
Suppress deprecation warnings for backward compatibility
aviralgarg05 Jan 12, 2026
c720a10
Merge upstream/main into fix/issue-15811
aviralgarg05 Feb 15, 2026
fa9133d
Address PR feedback: preserve special mappings and track 3.0 removal
aviralgarg05 Feb 19, 2026
8270514
Merge remote-tracking branch 'upstream/main' into fix/issue-15811
trask Feb 25, 2026
8213aed
Address remaining PR review feedback
aviralgarg05 Mar 30, 2026
b432212
Merge branch 'main' into fix/issue-15811
aviralgarg05 Mar 30, 2026
d02c1de
Merge remote-tracking branch 'upstream/main' into fix/issue-15811
trask May 4, 2026
74b8b25
Address remaining PR review feedback
aviralgarg05 May 5, 2026
346ed3d
Merge remote-tracking branch 'upstream/main' into fix/issue-15811
aviralgarg05 May 5, 2026
151b681
Merge remote-tracking branch 'origin/fix/issue-15811' into fix/issue-…
aviralgarg05 May 5, 2026
aaa02b3
fix: use Java-compatible empty map in config provider test
aviralgarg05 Jul 9, 2026
c1683da
fix: satisfy spotless for config provider test
aviralgarg05 Jul 9, 2026
7a34a99
configurable access path
zeitlinger Jul 14, 2026
15ce857
Merge remote-tracking branch 'origin/main' into cp-bridge-for-distros
zeitlinger Jul 14, 2026
7e7938f
add DeclarativeConfigPropertiesDurationUtil
zeitlinger Jul 14, 2026
2bc1684
Add contrib-facing declarative bridge helpers
zeitlinger Jul 14, 2026
640ea3c
cleanup
zeitlinger Jul 14, 2026
c825e84
Fix component provider example in bridge README
zeitlinger Jul 14, 2026
55f9e56
Update declarative-config-bridge/src/main/java/io/opentelemetry/instr…
zeitlinger Jul 15, 2026
05d1972
Fix declarative config bridge review findings
trask Jul 20, 2026
19e9f58
Rename declarative duration helper
trask Jul 20, 2026
264b8bd
Simplify declarative config bridge API
trask Jul 20, 2026
e8b277f
Scope deprecated API suppression
trask Jul 20, 2026
1aabda1
Address review comment from copilot-pull-request-reviewer: isolate co…
trask Jul 20, 2026
174e659
Address review comment from copilot-pull-request-reviewer: correct pr…
trask Jul 20, 2026
10fda27
Address review comment from copilot-pull-request-reviewer: narrow hel…
trask Jul 20, 2026
5920f40
Address review comment from copilot-pull-request-reviewer: document b…
trask Jul 20, 2026
8c61aa3
Merge remote-tracking branch 'upstream/main' into cp-bridge-for-contrib
trask Jul 20, 2026
eae11a0
spotless
trask Jul 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 32 additions & 35 deletions declarative-config-bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,47 @@
Declarative Config Bridge allows instrumentation authors to access configuration in a uniform way,
regardless of the configuration source.

The bridge allows you to read configuration using the system property style when dealing with
declarative configuration.
The bridge lets callers expose flat `ConfigProperties` through the declarative configuration API,
including custom property mappings and custom declarative/flat prefixes.

## Example

As an example, let's look at the inferred spans configuration.
First, there is a configuration method that reads the properties and is unaware of the source of the
configuration:
As an example, let's look at the contrib inferred spans configuration.
It reads declarative keys such as `backup_diagnostic_files`, while preserving flat property support
for `otel.inferred.spans.backup.diagnostic.files`.

```java
class InferredSpansConfig {
static SpanProcessor create(ConfigProperties properties) {
// read properties here
boolean backupDiagnosticFiles =
properties.getBoolean("otel.inferred.spans.backup.diagnostic.files", false);
static SpanProcessor createSpanProcessor(DeclarativeConfigProperties properties) {
boolean backupDiagnosticFiles = properties.getBoolean("backup_diagnostic_files", false);
}
}
```

The auto configuration **without declarative config** passes the provided properties directly:
The auto configuration path can bridge flat config into that declarative view:

```java

@AutoService(AutoConfigurationCustomizerProvider.class)
public class InferredSpansAutoConfig implements AutoConfigurationCustomizerProvider {

@Override
public void customize(AutoConfigurationCustomizer config) {
config.addTracerProviderCustomizer(
(providerBuilder, properties) -> {
providerBuilder.addSpanProcessor(InferredSpansConfig.create(properties));
DeclarativeConfigProperties declarativeProperties =
ConfigPropertiesBackedConfigProvider.builder()
.setAccessPath("", "otel.inferred.spans.")
.build(properties)
.getInstrumentationConfig();
providerBuilder.addSpanProcessor(
InferredSpansConfig.createSpanProcessor(declarativeProperties));
return providerBuilder;
});
}
}
```

The auto configuration **with declarative config** uses the Declarative Config Bridge to be able to
use common configuration method:
The declarative component provider can use the same config method directly:

Let's first look at the yaml file that is used to configure the inferred spans processor:

Expand All @@ -56,35 +58,30 @@ file_format: 1.1
tracer_provider:
processors:
- inferred_spans:
Comment thread
trask marked this conversation as resolved.
Outdated
backup:
diagnostic:
files: true
backup_diagnostic_files: true
```

And now the component provider that uses the Declarative Config Bridge:
And now the component provider:

```java

@AutoService(ComponentProvider.class)
public class InferredSpansComponentProvider implements ComponentProvider {
public class InferredSpansSpanProcessorProvider implements ComponentProvider {

@Override
public String getName() {
return "inferred_spans";
public SpanProcessor create(DeclarativeConfigProperties properties) {
return InferredSpansConfig.createSpanProcessor(properties);
}
Comment thread
zeitlinger marked this conversation as resolved.
}
```

@Override
public SpanProcessor create(DeclarativeConfigProperties config) {
return InferredSpansConfig.create(
new DeclarativeConfigPropertiesBridgeBuilder()
// crop the prefix, because the properties are under the "inferred_spans" processor
.addMapping("otel.inferred.spans.", "")
.build(config));
}
For duration properties, contrib's `span-stacktrace` and `inferred-spans` use
`DeclarativeConfigPropertiesDurationUtil.parseDuration(...)`:

@Override
public Class<SpanProcessor> getType() {
return SpanProcessor.class;
}
}
```java
Duration minDuration =
DeclarativeConfigPropertiesDurationUtil.parseDuration(properties, "min_duration");
```

String duration values such as `42ms` are supported when the declarative config is backed by flat
`ConfigProperties`. For other declarative-config implementations, durations must already be
normalized to integer milliseconds.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

package io.opentelemetry.instrumentation.config.bridge;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.HashMap;
import java.util.Map;

/**
* A {@link ConfigProvider} implementation backed by {@link ConfigProperties}.
Expand All @@ -20,13 +23,62 @@ public final class ConfigPropertiesBackedConfigProvider implements ConfigProvide
private final DeclarativeConfigProperties instrumentationConfig;

public static ConfigProvider create(ConfigProperties configProperties) {
return new ConfigPropertiesBackedConfigProvider(configProperties);
return new ConfigPropertiesBackedConfigProvider(
ConfigPropertiesBackedDeclarativeConfigProperties.createInstrumentationConfig(
configProperties));
}

private ConfigPropertiesBackedConfigProvider(ConfigProperties configProperties) {
this.instrumentationConfig =
ConfigPropertiesBackedDeclarativeConfigProperties.createInstrumentationConfig(
configProperties);
public static Builder builder() {
return new Builder();
}

private ConfigPropertiesBackedConfigProvider(DeclarativeConfigProperties instrumentationConfig) {
this.instrumentationConfig = instrumentationConfig;
}

public static final class Builder {
private final Map<String, String> mappings = new HashMap<>();
private String accessRoot =
ConfigPropertiesBackedDeclarativeConfigProperties.DEFAULT_ACCESS_ROOT;
private String resultPrefix =
ConfigPropertiesBackedDeclarativeConfigProperties.DEFAULT_RESULT_PREFIX;

private Builder() {}

/**
* Adds a mapping from a declarative property path to a flat {@link ConfigProperties} key.
*
* <p>This is useful when a component is configured under a custom declarative path but still
* wants to read an existing flat property name. For example, contrib's inferred spans component
* uses declarative keys like {@code backup_diagnostic_files} while reading {@code
* otel.inferred.spans.backup.diagnostic.files} from flat config.
*/
@CanIgnoreReturnValue
public Builder addMapping(String declarativeProperty, String configProperty) {
mappings.put(declarativeProperty, configProperty);
return this;
}

/**
* Sets the declarative path prefix that this bridge reads from and the flat-property prefix it
* resolves to.
*
* <p>This lets callers bridge a subtree directly instead of always starting from {@code java.}
* -> {@code otel.instrumentation.}. For example, contrib's inferred spans autoconfigure path
* reads the component root directly and resolves it against {@code otel.inferred.spans.}.
*/
@CanIgnoreReturnValue
public Builder setAccessPath(String accessRoot, String resultPrefix) {
this.accessRoot = accessRoot;
this.resultPrefix = resultPrefix;
return this;
}

public ConfigProvider build(ConfigProperties configProperties) {
return new ConfigPropertiesBackedConfigProvider(
ConfigPropertiesBackedDeclarativeConfigProperties.createInstrumentationConfig(
configProperties, mappings, accessRoot, resultPrefix));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -94,16 +97,44 @@ final class ConfigPropertiesBackedDeclarativeConfigProperties

private final ConfigProperties configProperties;
private final List<String> path;
private final Map<String, String> mappings;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 path)

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++) {
Expand All @@ -228,7 +259,7 @@ private String resolvePropertyKey(String name) {
translatedPath.append(translateName(segments[i]));
Comment thread
trask marked this conversation as resolved.
}

return "otel.instrumentation." + translatedPath;
return resultPrefix + translatedPath;
}

private String pathWithName(String name) {
Expand Down
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);
}
}
Loading
Loading