Skip to content

Commit cbf3ab8

Browse files
committed
[Issue open-telemetry#1107] Add support for gzip compression for OTLP exporter
1 parent be53564 commit cbf3ab8

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
StatusCode,
3232
insecure_channel,
3333
secure_channel,
34+
Compression
3435
)
3536

3637
from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue
@@ -126,6 +127,7 @@ class OTLPExporterMixin(
126127
endpoint: OpenTelemetry Collector receiver endpoint
127128
credentials: ChannelCredentials object for server authentication
128129
metadata: Metadata to send when exporting
130+
compression: Compression algorithm used in channel
129131
"""
130132

131133
def __init__(
@@ -140,12 +142,10 @@ def __init__(
140142
self._metadata = metadata
141143
self._collector_span_kwargs = None
142144

143-
if compression is None:
144-
self.compression = os.environ.get(
145-
"OTEL_EXPORTER_OTLP_COMPRESSION", DEFAULT_COMPRESSION
146-
)
145+
if compression is 'gzip':
146+
self.compression = Compression.Gzip
147147
else:
148-
self.compression = compression
148+
self.compression = Compression.NoCompression
149149

150150
if credentials is None:
151151
self._client = self._stub(insecure_channel(endpoint, compression=self.compression))

exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class OTLPSpanExporter(
5252
endpoint: OpenTelemetry Collector receiver endpoint
5353
credentials: Credentials object for server authentication
5454
metadata: Metadata to send when exporting
55+
compression: Compression algorithm to be used in channel
5556
"""
5657

5758
_result = SpanExportResult

exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
1517
from collections import OrderedDict
1618
from concurrent.futures import ThreadPoolExecutor
1719
from unittest import TestCase
1820
from unittest.mock import Mock, PropertyMock, patch
1921

2022
from google.protobuf.duration_pb2 import Duration
2123
from google.rpc.error_details_pb2 import RetryInfo
22-
from grpc import StatusCode, server
24+
from grpc import StatusCode, server, Compression
2325

2426
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
2527
from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import (
@@ -158,6 +160,19 @@ def setUp(self):
158160
def tearDown(self):
159161
self.server.stop(None)
160162

163+
def test_no_compression(self):
164+
"""Test default compression passed to constructor"""
165+
exporter = OTLPSpanExporter()
166+
167+
self.assertEqual(exporter.compression, Compression.NoCompression)
168+
169+
def test_gzip_compression(self):
170+
"""Test the compression argument passed to constructor."""
171+
compression = "gzip"
172+
exporter = OTLPSpanExporter(compression=compression)
173+
174+
self.assertEqual(exporter.compression, Compression.Gzip)
175+
161176
@patch("opentelemetry.exporter.otlp.exporter.expo")
162177
@patch("opentelemetry.exporter.otlp.exporter.sleep")
163178
def test_unavailable(self, mock_sleep, mock_expo):

0 commit comments

Comments
 (0)