Skip to content

Commit afe803e

Browse files
committed
comments
1 parent 80985e8 commit afe803e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Diff for: exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,23 @@
6161
}
6262

6363

64-
def environ_to_compression(environ_key: str) -> Optional[Compression]:
65-
environ_value = environ.get(environ_key)
66-
if environ_value not in _ENVIRON_TO_COMPRESSION:
67-
raise Exception(
64+
class InvalidCompressionValueException(Exception):
65+
def __init__(self, environ_key: str, environ_value: str):
66+
super().__init__(
6867
'Invalid value "{}" for compression envvar {}'.format(
6968
environ_value, environ_key
7069
)
7170
)
71+
72+
73+
def environ_to_compression(environ_key: str) -> Optional[Compression]:
74+
environ_value = (
75+
environ[environ_key].lower().strip()
76+
if environ_key in environ
77+
else None
78+
)
79+
if environ_value not in _ENVIRON_TO_COMPRESSION:
80+
raise InvalidCompressionValueException(environ_key, environ_value)
7281
return _ENVIRON_TO_COMPRESSION[environ_value]
7382

7483

Diff for: exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class OTLPSpanExporter(
7070
credentials: Credentials object for server authentication
7171
headers: Headers to send when exporting
7272
timeout: Backend request timeout in seconds
73+
compression: gRPC compression method to use
7374
"""
7475

7576
_result = SpanExportResult

Diff for: exporter/opentelemetry-exporter-otlp/tests/test_otlp_exporter_mixin.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
from unittest import TestCase
216
from unittest.mock import patch
317

@@ -12,13 +26,20 @@ def test_environ_to_compression(self):
1226
"os.environ",
1327
{
1428
"test_gzip": "gzip",
29+
"test_gzip_caseinsensitive_with_whitespace": " GzIp ",
1530
"test_deflate": "deflate",
1631
"test_invalid": "some invalid compression",
1732
},
1833
):
1934
self.assertEqual(
2035
environ_to_compression("test_gzip"), Compression.Gzip
2136
)
37+
self.assertEqual(
38+
environ_to_compression(
39+
"test_gzip_caseinsensitive_with_whitespace"
40+
),
41+
Compression.Gzip,
42+
)
2243
self.assertEqual(
2344
environ_to_compression("test_deflate"), Compression.Deflate
2445
)

0 commit comments

Comments
 (0)