Repository: open-telemetry/opentelemetry-python

Issue:
OTLP exporter must support gzip content encoding
As per spec https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/protocol/exporter.md#opentelemetry-protocol-exporter


Discussion:
Hi! Can I take on this issue? 
Sure!

Resolving patch:
diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/__init__.py
--- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/__init__.py
+++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/__init__.py
@@ -26,6 +26,16 @@
 .. _OTLP: https://github.com/open-telemetry/opentelemetry-collector/
 .. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
 
+.. envvar:: OTEL_EXPORTER_OTLP_COMPRESSION
+
+The :envvar:`OTEL_EXPORTER_OTLP_COMPRESSION` environment variable allows a
+compression algorithm to be passed to the OTLP exporter. The compression
+algorithms that are supported include gzip and no compression. The value should
+be in the format of a string "gzip" for gzip compression, and no value specified
+if no compression is the desired choice.
+Additional details are available `in the specification
+<https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/protocol/exporter.md#opentelemetry-protocol-exporter>`_.
+
 .. code:: python
 
     from opentelemetry import trace
diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
--- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
+++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
@@ -14,19 +14,20 @@
 
 """OTLP Exporter"""
 
+import enum
 import logging
-import os
 from abc import ABC, abstractmethod
 from collections.abc import Mapping, Sequence
 from time import sleep
 from typing import Any, Callable, Dict, Generic, List, Optional
 from typing import Sequence as TypingSequence
-from typing import Text, Tuple, TypeVar
+from typing import Text, TypeVar
 
 from backoff import expo
 from google.rpc.error_details_pb2 import RetryInfo
 from grpc import (
     ChannelCredentials,
+    Compression,
     RpcError,
     StatusCode,
     insecure_channel,
@@ -47,6 +48,10 @@
 ExportResultT = TypeVar("ExportResultT")
 
 
+class OTLPCompression(enum.Enum):
+    gzip = "gzip"
+
+
 def _translate_key_values(key: Text, value: Any) -> KeyValue:
 
     if isinstance(value, bool):
@@ -137,6 +142,7 @@ class OTLPExporterMixin(
         insecure: Connection type
         credentials: ChannelCredentials object for server authentication
         metadata: Metadata to send when exporting
+        compression: Compression algorithm to be used in channel
         timeout: Backend request timeout in seconds
     """
 
@@ -147,6 +153,7 @@ def __init__(
         credentials: Optional[ChannelCredentials] = None,
         headers: Optional[str] = None,
         timeout: Optional[int] = None,
+        compression: str = None,
     ):
         super().__init__()
 
@@ -169,13 +176,40 @@ def __init__(
         )
         self._collector_span_kwargs = None
 
+        if compression is None:
+            compression_algorithm = Compression.NoCompression
+        elif (
+            compression in OTLPCompression._value2member_map_
+            and OTLPCompression(compression) is OTLPCompression.gzip
+        ):
+            compression_algorithm = Compression.Gzip
+        else:
+            compression_str = Configuration().EXPORTER_OTLP_INSECURE or None
+            if compression_str is None:
+                compression_algorithm = Compression.NoCompression
+            elif (
+                compression_str in OTLPCompression._value2member_map_
+                and OTLPCompression(compression_str) is OTLPCompression.gzip
+            ):
+                compression_algorithm = Compression.Gzip
+            else:
+                raise ValueError(
+                    "OTEL_EXPORTER_OTLP_COMPRESSION environment variable does not match gzip."
+                )
+
         if insecure:
-            self._client = self._stub(insecure_channel(endpoint))
+            self._client = self._stub(
+                insecure_channel(endpoint, compression=compression_algorithm)
+            )
         else:
             credentials = credentials or _load_credential_from_file(
                 Configuration().EXPORTER_OTLP_CERTIFICATE
             )
-            self._client = self._stub(secure_channel(endpoint, credentials))
+            self._client = self._stub(
+                secure_channel(
+                    endpoint, credentials, compression=compression_algorithm
+                )
+            )
 
     @abstractmethod
     def _translate_data(


Test patch: