File tree Expand file tree Collapse file tree 9 files changed +30
-22
lines changed
exporter/opentelemetry-exporter-otlp-proto-http
src/opentelemetry/exporter/otlp/proto/http Expand file tree Collapse file tree 9 files changed +30
-22
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
- Update explicit histogram bucket boundaries
11
11
([ #2947 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2947 ) )
12
+ - ` exporter-otlp-proto-http ` : add user agent string
13
+ ([ #2959 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2959 ) )
12
14
13
15
## [ 1.13.0-0.34b0] ( https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.13.0 ) - 2022-09-26
14
16
Original file line number Diff line number Diff line change 71
71
"""
72
72
import enum
73
73
74
+ from .version import __version__
75
+
76
+
77
+ _OTLP_HTTP_HEADERS = {
78
+ "Content-Type" : "application/x-protobuf" ,
79
+ "User-Agent" : "OTel OTLP Exporter Python/" + __version__ ,
80
+ }
81
+
74
82
75
83
class Compression (enum .Enum ):
76
84
NoCompression = "none"
Original file line number Diff line number Diff line change 35
35
LogExportResult ,
36
36
LogData ,
37
37
)
38
- from opentelemetry .exporter .otlp .proto .http import Compression
38
+ from opentelemetry .exporter .otlp .proto .http import (
39
+ _OTLP_HTTP_HEADERS ,
40
+ Compression ,
41
+ )
39
42
from opentelemetry .exporter .otlp .proto .http ._log_exporter .encoder import (
40
43
_ProtobufEncoder ,
41
44
)
@@ -78,9 +81,7 @@ def __init__(
78
81
self ._compression = compression or _compression_from_env ()
79
82
self ._session = session or requests .Session ()
80
83
self ._session .headers .update (self ._headers )
81
- self ._session .headers .update (
82
- {"Content-Type" : _ProtobufEncoder ._CONTENT_TYPE }
83
- )
84
+ self ._session .headers .update (_OTLP_HTTP_HEADERS )
84
85
if self ._compression is not Compression .NoCompression :
85
86
self ._session .headers .update (
86
87
{"Content-Encoding" : self ._compression .value }
Original file line number Diff line number Diff line change 36
36
37
37
38
38
class _ProtobufEncoder :
39
- _CONTENT_TYPE = "application/x-protobuf"
40
-
41
39
@classmethod
42
40
def serialize (cls , batch : Sequence [LogData ]) -> str :
43
41
return cls .encode (batch ).SerializeToString ()
Original file line number Diff line number Diff line change 36
36
OTEL_EXPORTER_OTLP_TIMEOUT ,
37
37
)
38
38
from opentelemetry .sdk .trace .export import SpanExporter , SpanExportResult
39
- from opentelemetry .exporter .otlp .proto .http import Compression
39
+ from opentelemetry .exporter .otlp .proto .http import (
40
+ _OTLP_HTTP_HEADERS ,
41
+ Compression ,
42
+ )
40
43
from opentelemetry .exporter .otlp .proto .http .trace_exporter .encoder import (
41
44
_ProtobufEncoder ,
42
45
)
@@ -89,9 +92,7 @@ def __init__(
89
92
self ._compression = compression or _compression_from_env ()
90
93
self ._session = session or requests .Session ()
91
94
self ._session .headers .update (self ._headers )
92
- self ._session .headers .update (
93
- {"Content-Type" : _ProtobufEncoder ._CONTENT_TYPE }
94
- )
95
+ self ._session .headers .update (_OTLP_HTTP_HEADERS )
95
96
if self ._compression is not Compression .NoCompression :
96
97
self ._session .headers .update (
97
98
{"Content-Encoding" : self ._compression .value }
Original file line number Diff line number Diff line change 60
60
61
61
62
62
class _ProtobufEncoder :
63
- _CONTENT_TYPE = "application/x-protobuf"
64
-
65
63
@classmethod
66
64
def serialize (cls , sdk_spans : Sequence [SDKSpan ]) -> str :
67
65
return cls .encode (sdk_spans ).SerializeToString ()
Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ def test_constructor_default(self):
84
84
self .assertIs (exporter ._compression , DEFAULT_COMPRESSION )
85
85
self .assertEqual (exporter ._headers , {})
86
86
self .assertIsInstance (exporter ._session , requests .Session )
87
+ self .assertIn ("User-Agent" , exporter ._session .headers )
88
+ self .assertEqual (
89
+ exporter ._session .headers .get ("Content-Type" ),
90
+ "application/x-protobuf" ,
91
+ )
87
92
88
93
@patch .dict (
89
94
"os.environ" ,
@@ -154,11 +159,6 @@ def test_serialize(self):
154
159
expected_encoding .SerializeToString (),
155
160
)
156
161
157
- def test_content_type (self ):
158
- self .assertEqual (
159
- _ProtobufEncoder ._CONTENT_TYPE , "application/x-protobuf"
160
- )
161
-
162
162
@staticmethod
163
163
def _get_sdk_log_data () -> List [LogData ]:
164
164
log1 = LogData (
Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ def test_constructor_default(self):
58
58
self .assertIs (exporter ._compression , DEFAULT_COMPRESSION )
59
59
self .assertEqual (exporter ._headers , {})
60
60
self .assertIsInstance (exporter ._session , requests .Session )
61
+ self .assertIn ("User-Agent" , exporter ._session .headers )
62
+ self .assertEqual (
63
+ exporter ._session .headers .get ("Content-Type" ),
64
+ "application/x-protobuf" ,
65
+ )
61
66
62
67
@patch .dict (
63
68
"os.environ" ,
Original file line number Diff line number Diff line change @@ -69,11 +69,6 @@ def test_serialize(self):
69
69
expected_encoding .SerializeToString (),
70
70
)
71
71
72
- def test_content_type (self ):
73
- self .assertEqual (
74
- _ProtobufEncoder ._CONTENT_TYPE , "application/x-protobuf"
75
- )
76
-
77
72
@staticmethod
78
73
def get_exhaustive_otel_span_list () -> List [SDKSpan ]:
79
74
trace_id = 0x3E0C63257DE34C926F9EFCD03927272E
You can’t perform that action at this time.
0 commit comments