Skip to content

Commit ceaad7e

Browse files
Add DeprecatedConfigProperties and apply backward-compatible config rename
1 parent 464e9d5 commit ceaad7e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.internal;
7+
8+
import static java.util.Collections.emptyList;
9+
import static java.util.logging.Level.WARNING;
10+
11+
import java.util.List;
12+
import java.util.logging.Logger;
13+
14+
/**
15+
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
16+
* any time.
17+
*/
18+
@SuppressWarnings("unused")
19+
public final class DeprecatedConfigProperties {
20+
21+
private static final Logger logger = Logger.getLogger(DeprecatedConfigProperties.class.getName());
22+
23+
public static boolean getBoolean(
24+
String deprecatedPropertyName, String newPropertyName, boolean defaultValue) {
25+
26+
warnIfUsed(deprecatedPropertyName, newPropertyName);
27+
28+
boolean value = ConfigPropertiesUtil.getBoolean(deprecatedPropertyName, defaultValue);
29+
return ConfigPropertiesUtil.getBoolean(newPropertyName, value);
30+
}
31+
32+
public static List<String> getList(String deprecatedPropertyName, String newPropertyName) {
33+
34+
warnIfUsed(deprecatedPropertyName, newPropertyName);
35+
36+
List<String> value = ConfigPropertiesUtil.getList(deprecatedPropertyName, emptyList());
37+
return ConfigPropertiesUtil.getList(newPropertyName, value);
38+
}
39+
40+
private static void warnIfUsed(String deprecatedPropertyName, String newPropertyName) {
41+
if (ConfigPropertiesUtil.getString(deprecatedPropertyName) != null) {
42+
logger.log(
43+
WARNING,
44+
"Deprecated property \"{0}\" was used; use the \"{1}\" property instead",
45+
new Object[] {deprecatedPropertyName, newPropertyName});
46+
}
47+
}
48+
49+
private DeprecatedConfigProperties() {}
50+
}

0 commit comments

Comments
 (0)