java.lang.Object
io.opentelemetry.instrumentation.api.config.Config

public abstract class Config extends Object
Represents the global instrumentation configuration consisting of system properties and environment variables; and, if using the OpenTelemetry javaagent, contents of the agent configuration file and properties defined by the ContextCustomizer SPI implementations.

In case any get*() method variant gets called for the same property more than once (e.g. each time an advice class executes) it is suggested to cache the result instead of repeatedly calling Config. The instrumentation configuration does not change during the runtime so retrieving the property once and storing its result in a static final field allows JIT to do its magic and remove some code branches.

  • Method Summary

    Modifier and Type
    Method
    Description
    Start building a new Config instance.
    static Config
    get()
    Returns the global instrumentation configuration.
    abstract Map<String,String>
    Returns all properties stored in this Config instance.
    boolean
    getBoolean(String name, boolean defaultValue)
    Returns a boolean-valued configuration property or defaultValue if a property with name name has not been configured.
    double
    getDouble(String name, double defaultValue)
    Returns a double-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    getDuration(String name, Duration defaultValue)
    Returns a duration-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    int
    getInt(String name, int defaultValue)
    Returns an integer-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    getList(String name, List<String> defaultValue)
    Returns a list-valued configuration property or defaultValue if a property with name name has not been configured.
    long
    getLong(String name, long defaultValue)
    Returns a long-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    getMap(String name, Map<String,String> defaultValue)
    Returns a map-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    Returns a string-valued configuration property or null if a property with name name has not been configured.
    getString(String name, String defaultValue)
    Returns a string-valued configuration property or defaultValue if a property with name name has not been configured.
    static void
    Sets the instrumentation configuration singleton.
    Returns a new ConfigBuilder instance populated with the properties of this Config.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • builder

      public static ConfigBuilder builder()
      Start building a new Config instance.
    • internalInitializeConfig

      public static void internalInitializeConfig(Config config)
      Sets the instrumentation configuration singleton. This method is only supposed to be called once, during the javaagent initialization, just before get() is used for the first time.

      This method is internal and is hence not for public use. Its API is unstable and can change at any time.

    • get

      public static Config get()
      Returns the global instrumentation configuration.
    • getAllProperties

      public abstract Map<String,String> getAllProperties()
      Returns all properties stored in this Config instance. The returned map is unmodifiable.
    • getString

      @Nullable public String getString(String name)
      Returns a string-valued configuration property or null if a property with name name has not been configured.
    • getString

      public String getString(String name, String defaultValue)
      Returns a string-valued configuration property or defaultValue if a property with name name has not been configured.
    • getBoolean

      public boolean getBoolean(String name, boolean defaultValue)
      Returns a boolean-valued configuration property or defaultValue if a property with name name has not been configured.
    • getInt

      public int getInt(String name, int defaultValue)
      Returns an integer-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    • getLong

      public long getLong(String name, long defaultValue)
      Returns a long-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    • getDouble

      public double getDouble(String name, double defaultValue)
      Returns a double-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.
    • getDuration

      public Duration getDuration(String name, Duration defaultValue)
      Returns a duration-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed.

      Durations can be of the form "{number}{unit}", where unit is one of:

      • ms
      • s
      • m
      • h
      • d

      If no unit is specified, milliseconds is the assumed duration unit.

      Examples: 10s, 20ms, 5000

    • getList

      public List<String> getList(String name, List<String> defaultValue)
      Returns a list-valued configuration property or defaultValue if a property with name name has not been configured. The format of the original value must be comma-separated, e.g. one,two,three. The returned list is unmodifiable.
    • getMap

      public Map<String,String> getMap(String name, Map<String,String> defaultValue)
      Returns a map-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed. The format of the original value must be comma-separated for each key, with an '=' separating the key and value, e.g. key=value,anotherKey=anotherValue. The returned map is unmodifiable.
    • toBuilder

      public ConfigBuilder toBuilder()
      Returns a new ConfigBuilder instance populated with the properties of this Config.