77
88from opentelemetry import metrics
99from opentelemetry .sdk ._configuration ._common import (
10+ _map_compression ,
1011 _parse_headers ,
1112 load_entry_point ,
1213)
@@ -256,19 +257,6 @@ def _create_console_metric_exporter(
256257 )
257258
258259
259- def _map_compression_metric (
260- value : str | None , compression_enum : type
261- ) -> object | None :
262- """Map a compression string to the given Compression enum value."""
263- if value is None or value .lower () == "none" :
264- return None
265- if value .lower () == "gzip" :
266- return compression_enum .Gzip # type: ignore[attr-defined]
267- raise ConfigurationError (
268- f"Unsupported compression value '{ value } '. Supported values: 'gzip', 'none'."
269- )
270-
271-
272260def _create_otlp_http_metric_exporter (
273261 config : OtlpHttpMetricExporterConfig ,
274262) -> MetricExporter :
@@ -287,7 +275,9 @@ def _create_otlp_http_metric_exporter(
287275 "Install it with: pip install opentelemetry-exporter-otlp-proto-http"
288276 ) from exc
289277
290- compression = _map_compression_metric (config .compression , Compression )
278+ compression = _map_compression (
279+ config .compression , Compression , allow_deflate = True
280+ )
291281 headers = _parse_headers (config .headers , config .headers_list )
292282 timeout = (config .timeout / 1000.0 ) if config .timeout is not None else None
293283 preferred_temporality = _map_temporality (config .temporality_preference )
@@ -322,7 +312,7 @@ def _create_otlp_grpc_metric_exporter(
322312 "Install it with: pip install opentelemetry-exporter-otlp-proto-grpc"
323313 ) from exc
324314
325- compression = _map_compression_metric (config .compression , grpc .Compression )
315+ compression = _map_compression (config .compression , grpc .Compression )
326316 headers = _parse_headers (config .headers , config .headers_list )
327317 timeout = (config .timeout / 1000.0 ) if config .timeout is not None else None
328318 preferred_temporality = _map_temporality (config .temporality_preference )
0 commit comments