Select histogram aggregation with environment variables by ocelotl · Pull Request #3265 · open-telemetry/opentelemetry-python
| otel_exporter_otlp_metrics_temporality_preference = ( | |
| environ.get( | |
| OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, | |
| "CUMULATIVE", | |
| ) | |
| .upper() | |
| .strip() | |
| ) | |
| if otel_exporter_otlp_metrics_temporality_preference == "DELTA": | |
| instrument_class_temporality = { | |
| Counter: AggregationTemporality.DELTA, | |
| UpDownCounter: AggregationTemporality.CUMULATIVE, | |
| Histogram: AggregationTemporality.DELTA, | |
| ObservableCounter: AggregationTemporality.DELTA, | |
| ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, | |
| ObservableGauge: AggregationTemporality.CUMULATIVE, | |
| } | |
| elif otel_exporter_otlp_metrics_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: | |
| if otel_exporter_otlp_metrics_temporality_preference != ( | |
| "CUMULATIVE" | |
| ): | |
| _logger.warning( | |
| "Unrecognized OTEL_EXPORTER_METRICS_TEMPORALITY_PREFERENCE" | |
| " value found: " | |
| f"{otel_exporter_otlp_metrics_temporality_preference}, " | |
| "using CUMULATIVE" | |
| ) | |
| instrument_class_temporality = { | |
| Counter: AggregationTemporality.CUMULATIVE, | |
| UpDownCounter: AggregationTemporality.CUMULATIVE, | |
| Histogram: AggregationTemporality.CUMULATIVE, | |
| ObservableCounter: AggregationTemporality.CUMULATIVE, | |
| ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, | |
| ObservableGauge: AggregationTemporality.CUMULATIVE, | |
| } | |
| instrument_class_temporality.update(preferred_temporality or {}) |