DeprecatedConfigProperties.java 1.7 KB

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