Class Config
- java.lang.Object
-
- io.opentelemetry.instrumentation.api.config.Config
-
public abstract class Config extends Object
Represents the global agent configuration consisting of system properties, environment variables, contents of the agent configuration file and properties defined by theConfigPropertySourceSPI (seeConfigInitializerandConfigBuilder).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 callingConfig. Agent configuration does not change during the runtime so retrieving the property once and storing its result in e.g. static final field allows JIT to do its magic and remove some code branches.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PropertiesasJavaProperties()Deprecated.UsegetAllProperties()instead.static ConfigBuilderbuilder()Start building a newConfiginstance.static Configget()Returns the global agent configuration.abstract Map<String,String>getAllProperties()Returns all properties stored in this instance.BooleangetBoolean(String name)Returns a boolean-valued configuration property ornullif a property with namenamehas not been configured.booleangetBoolean(String name, boolean defaultValue)Returns a boolean-valued configuration property ordefaultValueif a property with namenamehas not been configured.DoublegetDouble(String name)Returns a double-valued configuration property ornullif a property with namenamehas not been configured.doublegetDouble(String name, double defaultValue)Returns a double-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed.DurationgetDuration(String name)Returns a duration-valued configuration property ornullif a property with namenamehas not been configured.DurationgetDuration(String name, Duration defaultValue)Returns a duration-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed.IntegergetInt(String name)Returns a integer-valued configuration property ornullif a property with namenamehas not been configured.intgetInt(String name, int defaultValue)Returns a integer-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed.List<String>getList(String name)Returns a list-valued configuration property or an empty list if a property with namenamehas not been configured.List<String>getList(String name, List<String> defaultValue)Returns a list-valued configuration property ordefaultValueif a property with namenamehas not been configured.LonggetLong(String name)Returns a long-valued configuration property ornullif a property with namenamehas not been configured.longgetLong(String name, long defaultValue)Returns a long-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed.Map<String,String>getMap(String name)Returns a map-valued configuration property or an empty map if a property with namenamehas not been configured.Map<String,String>getMap(String name, Map<String,String> defaultValue)Returns a map-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed.StringgetString(String name)Returns a string-valued configuration property ornullif a property with namenamehas not been configured.StringgetString(String name, String defaultValue)Returns a string-valued configuration property ordefaultValueif a property with namenamehas not been configured.static voidinternalInitializeConfig(Config config)Sets the agent configuration singleton.booleanisAgentDebugEnabled()booleanisInstrumentationEnabled(Iterable<String> instrumentationNames, boolean defaultEnabled)booleanisInstrumentationPropertyEnabled(Iterable<String> instrumentationNames, String suffix, boolean defaultEnabled)
-
-
-
Method Detail
-
builder
public static ConfigBuilder builder()
Start building a newConfiginstance.
-
internalInitializeConfig
public static void internalInitializeConfig(Config config)
Sets the agent configuration singleton. This method is only supposed to be called once, from the agent classloader just before the first instrumentation is loaded (and beforeget()is used for the first time).
-
get
public static Config get()
Returns the global agent configuration.
-
getAllProperties
public abstract Map<String,String> getAllProperties()
Returns all properties stored in this instance. The returned map is unmodifiable.
-
getString
@Nullable public String getString(String name)
Returns a string-valued configuration property ornullif a property with namenamehas not been configured.
-
getString
public String getString(String name, String defaultValue)
Returns a string-valued configuration property ordefaultValueif a property with namenamehas not been configured.
-
getBoolean
@Nullable public Boolean getBoolean(String name)
Returns a boolean-valued configuration property ornullif a property with namenamehas not been configured.
-
getBoolean
public boolean getBoolean(String name, boolean defaultValue)
Returns a boolean-valued configuration property ordefaultValueif a property with namenamehas not been configured.
-
getInt
@Nullable public Integer getInt(String name)
Returns a integer-valued configuration property ornullif a property with namenamehas not been configured.- Throws:
ConfigParsingException- if the property is not a valid integer.
-
getInt
public int getInt(String name, int defaultValue)
Returns a integer-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed. This is the safe variant ofgetInt(String).
-
getLong
@Nullable public Long getLong(String name)
Returns a long-valued configuration property ornullif a property with namenamehas not been configured.- Throws:
ConfigParsingException- if the property is not a valid long.
-
getLong
public long getLong(String name, long defaultValue)
Returns a long-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed. This is the safe variant ofgetLong(String).
-
getDouble
@Nullable public Double getDouble(String name)
Returns a double-valued configuration property ornullif a property with namenamehas not been configured.- Throws:
ConfigParsingException- if the property is not a valid long.
-
getDouble
public double getDouble(String name, double defaultValue)
Returns a double-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed. This is the safe variant ofgetDouble(String).
-
getDuration
@Nullable public Duration getDuration(String name)
Returns a duration-valued configuration property ornullif a property with namenamehas not been configured.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.
- Throws:
ConfigParsingException- if the property is not a valid long.
-
getDuration
public Duration getDuration(String name, Duration defaultValue)
Returns a duration-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed. This is the safe variant ofgetDuration(String).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.
-
getList
public List<String> getList(String name)
Returns a list-valued configuration property or an empty list if a property with namenamehas not been configured. The format of the original value must be comma-separated, e.g.one,two,three.
-
getList
public List<String> getList(String name, List<String> defaultValue)
Returns a list-valued configuration property ordefaultValueif a property with namenamehas not been configured. The format of the original value must be comma-separated, e.g.one,two,three.
-
getMap
public Map<String,String> getMap(String name)
Returns a map-valued configuration property or an empty map if a property with namenamehas not been configured. 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.- Throws:
ConfigParsingException- if the property is not a valid long.
-
getMap
public Map<String,String> getMap(String name, Map<String,String> defaultValue)
Returns a map-valued configuration property ordefaultValueif a property with namenamehas not been configured or when parsing has failed. This is the safe variant ofgetMap(String). 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.
-
isInstrumentationEnabled
public boolean isInstrumentationEnabled(Iterable<String> instrumentationNames, boolean defaultEnabled)
-
isInstrumentationPropertyEnabled
public boolean isInstrumentationPropertyEnabled(Iterable<String> instrumentationNames, String suffix, boolean defaultEnabled)
-
isAgentDebugEnabled
public boolean isAgentDebugEnabled()
-
asJavaProperties
@Deprecated public Properties asJavaProperties()
Deprecated.UsegetAllProperties()instead.Converts this config instance to JavaProperties.
-
-