Skip to content

Commit 52893c8

Browse files
committed
map "common-enabled"
1 parent f8cdbe6 commit 52893c8

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/DeclarativeConfigPropertiesBridge.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties {
5050

5151
private static final String OTEL_INSTRUMENTATION_PREFIX = "otel.instrumentation.";
5252

53+
private static final Map<String, String> MAPPING_RULES = new HashMap<>();
54+
5355
// The node at .instrumentation.java
5456
private final DeclarativeConfigProperties instrumentationJavaNode;
5557

58+
static {
59+
MAPPING_RULES.put("otel.instrumentation.common.default-enabled", "common.default.enabled");
60+
}
61+
5662
DeclarativeConfigPropertiesBridge(DeclarativeConfigProperties instrumentationNode) {
5763
instrumentationJavaNode = instrumentationNode.getStructured("java", empty());
5864
}
@@ -133,9 +139,8 @@ private <T> T getPropertyValue(
133139
if (!property.startsWith(OTEL_INSTRUMENTATION_PREFIX)) {
134140
return null;
135141
}
136-
String suffix = property.substring(OTEL_INSTRUMENTATION_PREFIX.length()).replace('-', '_');
137142
// Split the remainder of the property on ".", and walk to the N-1 entry
138-
String[] segments = suffix.split("\\.");
143+
String[] segments = getSuffix(property).split("\\.");
139144
if (segments.length == 0) {
140145
return null;
141146
}
@@ -148,4 +153,13 @@ private <T> T getPropertyValue(
148153
String lastPart = segments[segments.length - 1];
149154
return extractor.apply(target, lastPart);
150155
}
156+
157+
private static String getSuffix(String property) {
158+
String special = MAPPING_RULES.get(property);
159+
if (special != null) {
160+
return special;
161+
}
162+
163+
return property.substring(OTEL_INSTRUMENTATION_PREFIX.length()).replace('-', '_');
164+
}
151165
}

javaagent-extension-api/src/test/java/io/opentelemetry/javaagent/extension/DeclarativeConfigPropertiesBridgeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class DeclarativeConfigPropertiesBridgeTest {
2929
+ "instrumentation/development:\n"
3030
+ " java:\n"
3131
+ " common:\n"
32-
+ " default_enabled: true\n"
32+
+ " default:\n"
33+
+ " enabled: true\n"
3334
+ " runtime_telemetry:\n"
3435
+ " enabled: false\n"
3536
+ " example_instrumentation:\n"

javaagent-tooling/src/test/resources/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
instrumentation:
22
java:
33
common:
4-
default_enabled: true
4+
default:
5+
enabled: true
56
runtime_telemetry:
67
enabled: false
78
external_annotations:

0 commit comments

Comments
 (0)