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:

  1. OPENTELEMETRY_PYTHON_SOMETHING

  2. OPENTELEMETRY_PYTHON_SOMETHING_ELSE_

  3. OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND__ELSE

4. OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else 4. OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else2

These won’t:

  1. OPENTELEMETRY_PYTH_SOMETHING

  2. OPENTELEMETRY_PYTHON_2_SOMETHING_AND__ELSE

  3. 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

  1. OPENTELEMETRY_PYTHON_METER_PROVIDER

  2. 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).

class opentelemetry.configuration.Configuration[source]

Bases: object