77
88from opentelemetry import metrics
99from opentelemetry .sdk ._configuration ._common import (
10+ _map_compression ,
1011 _parse_headers ,
1112 load_entry_point ,
1213)
@@ -265,19 +266,6 @@ def _create_console_metric_exporter(
265266 )
266267
267268
268- def _map_compression_metric (
269- value : str | None , compression_enum : type
270- ) -> object | None :
271- """Map a compression string to the given Compression enum value."""
272- if value is None or value .lower () == "none" :
273- return None
274- if value .lower () == "gzip" :
275- return compression_enum .Gzip # type: ignore[attr-defined]
276- raise ConfigurationError (
277- f"Unsupported compression value '{ value } '. Supported values: 'gzip', 'none'."
278- )
279-
280-
281269def _create_otlp_http_metric_exporter (
282270 config : OtlpHttpMetricExporterConfig ,
283271) -> MetricExporter :
@@ -296,7 +284,9 @@ def _create_otlp_http_metric_exporter(
296284 "Install it with: pip install opentelemetry-exporter-otlp-proto-http"
297285 ) from exc
298286
299- compression = _map_compression_metric (config .compression , Compression )
287+ compression = _map_compression (
288+ config .compression , Compression , allow_deflate = True
289+ )
300290 headers = _parse_headers (config .headers , config .headers_list )
301291 timeout = (config .timeout / 1000.0 ) if config .timeout is not None else None
302292 preferred_temporality = _map_temporality (config .temporality_preference )
@@ -331,7 +321,7 @@ def _create_otlp_grpc_metric_exporter(
331321 "Install it with: pip install opentelemetry-exporter-otlp-proto-grpc"
332322 ) from exc
333323
334- compression = _map_compression_metric (config .compression , grpc .Compression )
324+ compression = _map_compression (config .compression , grpc .Compression )
335325 headers = _parse_headers (config .headers , config .headers_list )
336326 timeout = (config .timeout / 1000.0 ) if config .timeout is not None else None
337327 preferred_temporality = _map_temporality (config .temporality_preference )
0 commit comments