opentelemetry.configuration module¶
Module contents¶
Simple configuration manager
This is a configuration manager for OpenTelemetry. It reads configuration
values from environment variables prefixed with OPENTELEMETRY_PYTHON_
whose
characters are only alphanumeric characters and unserscores, except for the
first character after OPENTELEMETRY_PYTHON_
which must not be a number.
For example, these environment variables will be read:
OPENTELEMETRY_PYTHON_SOMETHING
OPENTELEMETRY_PYTHON_SOMETHING_ELSE_
OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND__ELSE
OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else
OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else2
These won’t:
OPENTELEMETRY_PYTH_SOMETHING
OPENTELEMETRY_PYTHON_2_SOMETHING_AND__ELSE
OPENTELEMETRY_PYTHON_SOMETHING_%_ELSE
The values stored in the environment variables can be found in an instance of
opentelemetry.configuration.Configuration
. This class can be instantiated
freely because instantiating it returns always the same object.
For example, if the environment variable
OPENTELEMETRY_PYTHON_METER_PROVIDER
value is my_meter_provider
, then
Configuration().meter_provider == "my_meter_provider"
would be True
.
Non defined attributes will always return None
. This is intended to make it
easier to use the Configuration
object in actual code, because it won’t be
necessary to check for the attribute to be defined first.
Environment variables used by OpenTelemetry¶
OPENTELEMETRY_PYTHON_METER_PROVIDER
OPENTELEMETRY_PYTHON_TRACER_PROVIDER
The value of these environment variables should be the name of the entry point that points to the class that implements either provider. This OpenTelemetry API package provides one entry point for each, which can be found in the setup.py file:
entry_points={
...
"opentelemetry_meter_provider": [
"default_meter_provider = "
"opentelemetry.metrics:DefaultMeterProvider"
],
"opentelemetry_tracer_provider": [
"default_tracer_provider = "
"opentelemetry.trace:DefaultTracerProvider"
],
}
To use the meter provider above, then the
OPENTELEMETRY_PYTHON_METER_PROVIDER
should be set to
"default_meter_provider"
(this is not actually necessary since the
OpenTelemetry API provided providers are the default ones used if no
configuration is found in the environment variables).
Configuration values that are exactly "True"
or "False"
will be
converted to its boolean values of True
and False
respectively.
Configuration values that can be casted to integers or floats will be casted.
This object can be used by any OpenTelemetry component, native or external.
For that reason, the Configuration
object is designed to be immutable.
If a component would change the value of one of the Configuration
object
attributes then another component that relied on that value may break, leading
to bugs that are very hard to debug. To avoid this situation, the preferred
approach for components that need a different value than the one provided by
the Configuration
object is to implement a mechanism that allows the user
to override this value instead of changing it.