diff --git a/declarative-config-bridge/src/main/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridge.java b/declarative-config-bridge/src/main/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridge.java index 0421148323e6..314c99d6b5ed 100644 --- a/declarative-config-bridge/src/main/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridge.java +++ b/declarative-config-bridge/src/main/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridge.java @@ -17,6 +17,7 @@ import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Function; +import java.util.regex.Pattern; import javax.annotation.Nullable; /** @@ -51,6 +52,9 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties { private static final String OTEL_INSTRUMENTATION_PREFIX = "otel.instrumentation."; + private static final Pattern EXPERIMENTAL_PATTERN = Pattern.compile("\\.experimental[.-]([^.]+)"); + private static final Pattern EXPERIMENTAL_IN_NAME_PATTERN = + Pattern.compile("\\.([^.]+experimental[^.]+)"); private final DeclarativeConfigProperties baseNode; @@ -178,11 +182,22 @@ private T getPropertyValue( } static String[] getSegments(String property) { + // Remove "otel.instrumentation." prefix if present if (property.startsWith(OTEL_INSTRUMENTATION_PREFIX)) { property = property.substring(OTEL_INSTRUMENTATION_PREFIX.length()); } - // Split the remainder of the property on "." - return property.replace('-', '_').split("\\."); + + // Transform experimental patterns: + // - ".experimental-foo" or ".experimental.foo" becomes ".foo/development" + String transformed = EXPERIMENTAL_PATTERN.matcher(property).replaceAll(".$1/development"); + // - ".foo-experimental-bar" becomes ".foo_experimental_bar/development" + transformed = EXPERIMENTAL_IN_NAME_PATTERN.matcher(transformed).replaceAll(".$1/development"); + + // Replace dashes with underscores for property normalization + transformed = transformed.replace('-', '_'); + + // Split into segments on dots + return transformed.split("\\."); } private String translateProperty(String property) { diff --git a/declarative-config-bridge/src/test/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridgeTest.java b/declarative-config-bridge/src/test/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridgeTest.java index 29f9d424cd9d..d4718a4fa40c 100644 --- a/declarative-config-bridge/src/test/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridgeTest.java +++ b/declarative-config-bridge/src/test/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridgeTest.java @@ -60,7 +60,7 @@ void getProperties() { .isTrue(); // common cases - assertThat(bridge.getBoolean("otel.instrumentation.runtime-telemetry.enabled")).isFalse(); + assertThat(bridge.getBoolean("otel.instrumentation.runtime-telemetry.enabled")).isTrue(); // check all the types Map expectedMap = new HashMap<>(); @@ -141,4 +141,18 @@ void agentTranslation() { assertThat(bridge.getBoolean("otel.javaagent.experimental.indy")).isTrue(); assertThat(bridge.getString("otel.javaagent.logging")).isEqualTo("application"); } + + @Test + void developmentTranslation() { + String prefix = "otel.instrumentation.runtime-telemetry"; + assertThat(bridge.getBoolean(prefix + ".experimental-gc-profiler.experimental-metrics")) + .isTrue(); + assertThat(bridge.getBoolean(prefix + ".experimental.gc-profiler.experimental.metrics")) + .isTrue(); + + // experimental in the middle of the property name should be preserved + assertThat( + bridge.getBoolean("otel.instrumentation.runtime-telemetry.emit-experimental-telemetry")) + .isTrue(); + } } diff --git a/declarative-config-bridge/src/test/resources/config.yaml b/declarative-config-bridge/src/test/resources/config.yaml index 5f8bbd1943b0..9f3b591c4cfb 100644 --- a/declarative-config-bridge/src/test/resources/config.yaml +++ b/declarative-config-bridge/src/test/resources/config.yaml @@ -5,10 +5,12 @@ instrumentation/development: full_name: preserved: true agent: - experimental: - indy: true + indy/development: true runtime_telemetry: - enabled: false + emit_experimental_telemetry/development: true + enabled: true + gc_profiler/development: + metrics/development: true example_instrumentation: string_key: value bool_key: true diff --git a/instrumentation-api-incubator/javaagent-testing/src/test/resources/declarative-config.yaml b/instrumentation-api-incubator/javaagent-testing/src/test/resources/declarative-config.yaml index 8c6c7dbe60ef..18379249f803 100644 --- a/instrumentation-api-incubator/javaagent-testing/src/test/resources/declarative-config.yaml +++ b/instrumentation-api-incubator/javaagent-testing/src/test/resources/declarative-config.yaml @@ -5,7 +5,7 @@ instrumentation/development: java: http: client: - emit_experimental_telemetry: true + emit_experimental_telemetry/development: true url_template_rules: - pattern: "http://localhost:.*/hello/.*" template: "/hello/*" diff --git a/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/resources/application.yaml b/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/resources/application.yaml index 6b24c0ee67fa..6a552dba4218 100644 --- a/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/resources/application.yaml +++ b/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/resources/application.yaml @@ -41,7 +41,7 @@ otel: instrumentation/development: java: runtime-telemetry: - emit_experimental_telemetry: true + emit_experimental_telemetry/development: true http: client: - emit_experimental_telemetry: true + emit_experimental_telemetry/development: true diff --git a/smoke-tests-otel-starter/spring-boot-3.2/src/main/resources/application.yaml b/smoke-tests-otel-starter/spring-boot-3.2/src/main/resources/application.yaml index 0533d63c9b88..924a63db7be1 100644 --- a/smoke-tests-otel-starter/spring-boot-3.2/src/main/resources/application.yaml +++ b/smoke-tests-otel-starter/spring-boot-3.2/src/main/resources/application.yaml @@ -41,7 +41,7 @@ otel: instrumentation/development: java: runtime-telemetry: - emit_experimental_telemetry: true + emit_experimental_telemetry/development: true http: client: - emit_experimental_telemetry: true + emit_experimental_telemetry/development: true