From 796e586376c55a82210f639e69523bf17a15552f Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 18 Apr 2023 00:08:35 -0600 Subject: [PATCH] Use LOWMEMORY as default temporality (#150) --- src/opentelemetry/launcher/configuration.py | 26 +++++++++++++++++---- tests/test_configuration.py | 4 ++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/opentelemetry/launcher/configuration.py b/src/opentelemetry/launcher/configuration.py index 4398014..e41adf9 100644 --- a/src/opentelemetry/launcher/configuration.py +++ b/src/opentelemetry/launcher/configuration.py @@ -100,7 +100,7 @@ "OTEL_EXPORTER_OTLP_TRACES_INSECURE", False ) _OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE = _env.str( - "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE", "CUMULATIVE" + "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE", "LOWMEMORY" ) _OTEL_METRIC_EXPORT_INTERVAL = _env.int("OTEL_METRIC_EXPORT_INTERVAL", 60000) @@ -179,8 +179,8 @@ def configure_opentelemetry( exported. Defaults to `ingest.lightstep.com:443`. metrics_exporter_temporality_preference (str): OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, The preferred association between instrument type and temporality, - meaningless if `metrics_enabled` is `False`. Can be `DELTA` or - `CUMULATIVE`, defaults to `CUMULATIVE`. + meaningless if `metrics_enabled` is `False`. Can be `DELTA`, + `CUMULATIVE` or `LOWMEMORY`, defaults to `LOWMEMORY`. If `CUMULATIVE`: @@ -199,6 +199,15 @@ def configure_opentelemetry( `ObservableCounter`: `DELTA` `ObservableUpDownCounter`: `CUMULATIVE` `ObservableGauge`: `CUMULATIVE` + + If `LOWMEMORY`: + + `Counter`: `DELTA` + `UpDownCounter`: `CUMULATIVE` + `Histogram`: `DELTA` + `ObservableCounter`: `CUMULATIVE` + `ObservableUpDownCounter`: `CUMULATIVE` + `ObservableGauge`: `CUMULATIVE` metrics_exporter_interval (int): OTEL_METRIC_EXPORT_INTERVAL, the periodic interval in miliseconds to wait before exporting metrics. service_name (str): OTEL_SERVICE_NAME, the name of the service that is @@ -454,12 +463,21 @@ def configure_opentelemetry( ObservableGauge: AggregationTemporality.CUMULATIVE, } + elif metrics_exporter_temporality_preference == "LOWMEMORY": + instrument_class_temporality = { + Counter: AggregationTemporality.DELTA, + UpDownCounter: AggregationTemporality.CUMULATIVE, + Histogram: AggregationTemporality.DELTA, + ObservableCounter: AggregationTemporality.CUMULATIVE, + ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, + ObservableGauge: AggregationTemporality.CUMULATIVE, + } else: message = ( f"Invalid configuration: " f"invalid metrics_exporter_temporality_preference: " f"{metrics_exporter_temporality_preference}. It must be " - f"DELTA or CUMULATIVE." + f"DELTA, CUMULATIVE or LOWMEMORY." ) _logger.error(message) raise InvalidConfigurationError(message) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index eb48fa0..07dcc85 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -68,9 +68,9 @@ def test_metrics_enabled(self, mock_metrics_exporter): credentials=ANY, headers=(("lightstep-access-token", "a" * 104),), preferred_temporality={ - Counter: AggregationTemporality.CUMULATIVE, + Counter: AggregationTemporality.DELTA, UpDownCounter: AggregationTemporality.CUMULATIVE, - Histogram: AggregationTemporality.CUMULATIVE, + Histogram: AggregationTemporality.DELTA, ObservableCounter: AggregationTemporality.CUMULATIVE, ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, ObservableGauge: AggregationTemporality.CUMULATIVE,