Skip to content

Commit cf4cec7

Browse files
committed
support gcp use case
1 parent a3cdc34 commit cf4cec7

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.incubator.config.bridge;
7+
8+
public final class ConfigPropertiesUtil {
9+
private ConfigPropertiesUtil() {}
10+
11+
public static String propertyYamlPath(String propertyName) {
12+
return yamlPath(propertyName);
13+
}
14+
15+
static String yamlPath(String property) {
16+
String[] segments = DeclarativeConfigPropertiesBridge.getSegments(property);
17+
if (segments.length == 0) {
18+
throw new IllegalArgumentException("Invalid property: " + property);
19+
}
20+
21+
return "'instrumentation/development' / 'java' / '" + String.join("' / '", segments) + "'";
22+
}
23+
}

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/bridge/DeclarativeConfigPropertiesBridge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private <T> T getPropertyValue(
169169
return extractor.apply(target, lastPart);
170170
}
171171

172-
private static String[] getSegments(String property) {
172+
static String[] getSegments(String property) {
173173
if (property.startsWith(OTEL_INSTRUMENTATION_PREFIX)) {
174174
property = property.substring(OTEL_INSTRUMENTATION_PREFIX.length());
175175
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.incubator.config.bridge;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
class ConfigPropertiesUtilTest {
13+
@Test
14+
void propertyYamlPath() {
15+
assertThat(ConfigPropertiesUtil.propertyYamlPath("google.otel.auth.target.signals"))
16+
.isEqualTo(
17+
"'instrumentation/development' / 'java' / 'google' / 'otel' / 'auth' / 'target' / 'signals'");
18+
}
19+
}

0 commit comments

Comments
 (0)