Skip to content

Commit ad104ee

Browse files
committed
map agent props
1 parent aff8f82 commit ad104ee

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public final class DeclarativeConfigPropertiesBridge implements ConfigProperties
5656

5757
// The node at .instrumentation.java
5858
private final DeclarativeConfigProperties instrumentationJavaNode;
59+
5960
// todo
60-
// private final DeclarativeConfigProperties instrumentationGeneralNode;
61+
// private final DeclarativeConfigProperties instrumentationGeneralNode;
6162

6263
static {
6364
MAPPING_RULES.put("otel.instrumentation.common.default-enabled", "common.default.enabled");
@@ -69,7 +70,7 @@ public DeclarativeConfigPropertiesBridge(ConfigProvider configProvider) {
6970
inst = DeclarativeConfigProperties.empty();
7071
}
7172
instrumentationJavaNode = inst.getStructured("java", empty());
72-
// instrumentationGeneralNode = inst.getStructured("general", empty());
73+
// instrumentationGeneralNode = inst.getStructured("general", empty());
7374
}
7475

7576
@Nullable
@@ -145,12 +146,13 @@ public Map<String, String> getMap(String propertyName) {
145146
@Nullable
146147
private <T> T getPropertyValue(
147148
String property, BiFunction<DeclarativeConfigProperties, String, T> extractor) {
148-
if (!property.startsWith(OTEL_INSTRUMENTATION_PREFIX)
149-
&& !property.startsWith(OTEL_JAVA_AGENT_PREFIX)) {
149+
String suffix = getSuffix(property);
150+
if (suffix == null) {
150151
return null;
151152
}
153+
152154
// Split the remainder of the property on ".", and walk to the N-1 entry
153-
String[] segments = getSuffix(property).split("\\.");
155+
String[] segments = suffix.split("\\.");
154156
if (segments.length == 0) {
155157
return null;
156158
}
@@ -170,6 +172,11 @@ private static String getSuffix(String property) {
170172
return special;
171173
}
172174

173-
return property.substring(OTEL_INSTRUMENTATION_PREFIX.length()).replace('-', '_');
175+
if (property.startsWith(OTEL_INSTRUMENTATION_PREFIX)) {
176+
return property.substring(OTEL_INSTRUMENTATION_PREFIX.length()).replace('-', '_');
177+
} else if (property.startsWith(OTEL_JAVA_AGENT_PREFIX)) {
178+
return "agent." + property.substring(OTEL_JAVA_AGENT_PREFIX.length()).replace('-', '_');
179+
}
180+
return null;
174181
}
175182
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ void getProperties() {
108108
assertThat(bridge.getMap("otel.instrumentation.other-instrumentation.map_key", expectedMap))
109109
.isEqualTo(expectedMap);
110110

111-
// todo agent properties
112-
// assertThat(bridge.getBoolean("otel.javaagent.enabled")).isFalse();
111+
assertThat(bridge.getBoolean("otel.javaagent.experimental.indy")).isTrue();
113112
}
114113
}

javaagent-extension-api/src/test/resources/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ file_format: 0.4
33
instrumentation/development:
44
java:
55
agent:
6+
experimental:
7+
indy: true
68
common:
79
default:
810
enabled: true

0 commit comments

Comments
 (0)