File tree 3 files changed +35
-4
lines changed
exporter/opentelemetry-exporter-otlp
src/opentelemetry/exporter/otlp
3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 61
61
}
62
62
63
63
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__ (
68
67
'Invalid value "{}" for compression envvar {}' .format (
69
68
environ_value , environ_key
70
69
)
71
70
)
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 )
72
81
return _ENVIRON_TO_COMPRESSION [environ_value ]
73
82
74
83
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ class OTLPSpanExporter(
70
70
credentials: Credentials object for server authentication
71
71
headers: Headers to send when exporting
72
72
timeout: Backend request timeout in seconds
73
+ compression: gRPC compression method to use
73
74
"""
74
75
75
76
_result = SpanExportResult
Original file line number Diff line number Diff line change
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
+
1
15
from unittest import TestCase
2
16
from unittest .mock import patch
3
17
@@ -12,13 +26,20 @@ def test_environ_to_compression(self):
12
26
"os.environ" ,
13
27
{
14
28
"test_gzip" : "gzip" ,
29
+ "test_gzip_caseinsensitive_with_whitespace" : " GzIp " ,
15
30
"test_deflate" : "deflate" ,
16
31
"test_invalid" : "some invalid compression" ,
17
32
},
18
33
):
19
34
self .assertEqual (
20
35
environ_to_compression ("test_gzip" ), Compression .Gzip
21
36
)
37
+ self .assertEqual (
38
+ environ_to_compression (
39
+ "test_gzip_caseinsensitive_with_whitespace"
40
+ ),
41
+ Compression .Gzip ,
42
+ )
22
43
self .assertEqual (
23
44
environ_to_compression ("test_deflate" ), Compression .Deflate
24
45
)
You can’t perform that action at this time.
0 commit comments