Skip to content

Commit

Permalink
[Issue open-telemetry#1107] Add gzip compression support for OTLP exp…
Browse files Browse the repository at this point in the history
…orter
  • Loading branch information
wilguo committed Sep 20, 2020
1 parent e8f5eb5 commit 3e82aed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
StatusCode,
insecure_channel,
secure_channel,
Compression
)

from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue
Expand Down Expand Up @@ -123,6 +124,7 @@ class OTLPExporterMixin(
endpoint: OpenTelemetry Collector receiver endpoint
credentials: ChannelCredentials object for server authentication
metadata: Metadata to send when exporting
compression: Compression algorithm used in channel
"""

def __init__(
Expand All @@ -136,6 +138,14 @@ def __init__(
self._metadata = metadata
self._collector_span_kwargs = None

<<<<<<< HEAD
=======
if compression is 'gzip':
self.compression = Compression.Gzip
else:
self.compression = Compression.NoCompression

>>>>>>> cbf3ab8... [Issue #1107] Add support for gzip compression for OTLP exporter
if credentials is None:
self._client = self._stub(insecure_channel(endpoint))
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class OTLPSpanExporter(
endpoint: OpenTelemetry Collector receiver endpoint
credentials: Credentials object for server authentication
metadata: Metadata to send when exporting
compression: Compression algorithm to be used in channel
"""

_result = SpanExportResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from collections import OrderedDict
from concurrent.futures import ThreadPoolExecutor
from unittest import TestCase
from unittest.mock import Mock, PropertyMock, patch

from google.protobuf.duration_pb2 import Duration
from google.rpc.error_details_pb2 import RetryInfo
from grpc import StatusCode, server
from grpc import StatusCode, server, Compression

from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import (
Expand Down Expand Up @@ -158,6 +160,19 @@ def setUp(self):
def tearDown(self):
self.server.stop(None)

def test_no_compression(self):
"""Test default compression passed to constructor"""
exporter = OTLPSpanExporter()

self.assertEqual(exporter.compression, Compression.NoCompression)

def test_gzip_compression(self):
"""Test the compression argument passed to constructor."""
compression = "gzip"
exporter = OTLPSpanExporter(compression=compression)

self.assertEqual(exporter.compression, Compression.Gzip)

@patch("opentelemetry.exporter.otlp.exporter.expo")
@patch("opentelemetry.exporter.otlp.exporter.sleep")
def test_unavailable(self, mock_sleep, mock_expo):
Expand Down

0 comments on commit 3e82aed

Please sign in to comment.