Top Description Constructors Methods
io.opentelemetry.api.internal

public final Class ConfigUtil

extends Object
Class Inheritance
Imports
java.util.ConcurrentModificationException, .Locale, .Map, .Properties, javax.annotation.Nullable

Configuration utilities.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <T> T
defaultIfNull(T value, T defaultValue)

Returns defaultValue if value is null, otherwise value.

public static String

Returns:

the system property if not null, or the environment variable if not null, or defaultValue
getString
(String
the property key
key
,
String defaultValue)

Return the system property or environment variable for the key.

public static String
normalizeEnvironmentVariableKey(String key)

Normalize an environment variable key by converting to lower case and replacing "_" with ".".

public static String
normalizePropertyKey(String key)

Normalize a property key by converting to lower case and replacing "-" with ".".

public static Properties
safeSystemProperties()

Returns a copy of system properties which is safe to iterate over.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ConfigUtilback to summary
private ConfigUtil()

Method Detail

defaultIfNullback to summary
public static <T> T defaultIfNull(T value, T defaultValue)

Returns defaultValue if value is null, otherwise value. This is an internal method.

getStringback to summary
public static String getString(String key, String defaultValue)

Return the system property or environment variable for the key.

Normalize the key using normalizePropertyKey(String). Match to system property keys also normalized with normalizePropertyKey(String). Match to environment variable keys normalized with normalizeEnvironmentVariableKey(String). System properties take priority over environment variables.

Parameters
key:String

the property key

Returns:String

the system property if not null, or the environment variable if not null, or defaultValue

normalizeEnvironmentVariableKeyback to summary
public static String normalizeEnvironmentVariableKey(String key)

Normalize an environment variable key by converting to lower case and replacing "_" with ".".

normalizePropertyKeyback to summary
public static String normalizePropertyKey(String key)

Normalize a property key by converting to lower case and replacing "-" with ".".

safeSystemPropertiesback to summary
public static Properties safeSystemProperties()

Returns a copy of system properties which is safe to iterate over.

In java 8 and android environments, iterating through system properties may trigger ConcurrentModificationException. This method ensures callers can iterate safely without risk of exception. See https://github.com/open-telemetry/opentelemetry-java/issues/6732 for details.