File tree 3 files changed +18
-4
lines changed
exporter/opentelemetry-exporter-otlp-proto-http
src/opentelemetry/exporter/otlp/proto/http/metric_exporter
3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## Unreleased
9
9
10
+ - Fix user agent in OTLP HTTP metrics exporter
11
+ ([ #4475 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/4475 ) )
12
+
10
13
## Version 1.31.0/0.52b0 (2025-03-12)
11
14
12
15
- semantic-conventions: Bump to 1.31.0
Original file line number Diff line number Diff line change 40
40
from opentelemetry .exporter .otlp .proto .common .metrics_encoder import (
41
41
encode_metrics ,
42
42
)
43
- from opentelemetry .exporter .otlp .proto .http import Compression
43
+ from opentelemetry .exporter .otlp .proto .http import (
44
+ _OTLP_HTTP_HEADERS ,
45
+ Compression ,
46
+ )
44
47
from opentelemetry .proto .collector .metrics .v1 .metrics_service_pb2 import ( # noqa: F401
45
48
ExportMetricsServiceRequest ,
46
49
)
@@ -152,9 +155,7 @@ def __init__(
152
155
self ._compression = compression or _compression_from_env ()
153
156
self ._session = session or requests .Session ()
154
157
self ._session .headers .update (self ._headers )
155
- self ._session .headers .update (
156
- {"Content-Type" : "application/x-protobuf" }
157
- )
158
+ self ._session .headers .update (_OTLP_HTTP_HEADERS )
158
159
if self ._compression is not Compression .NoCompression :
159
160
self ._session .headers .update (
160
161
{"Content-Encoding" : self ._compression .value }
Original file line number Diff line number Diff line change 32
32
DEFAULT_TIMEOUT ,
33
33
OTLPMetricExporter ,
34
34
)
35
+ from opentelemetry .exporter .otlp .proto .http .version import __version__
35
36
from opentelemetry .sdk .environment_variables import (
36
37
OTEL_EXPORTER_OTLP_CERTIFICATE ,
37
38
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE ,
@@ -124,6 +125,15 @@ def test_constructor_default(self):
124
125
self .assertIs (exporter ._compression , DEFAULT_COMPRESSION )
125
126
self .assertEqual (exporter ._headers , {})
126
127
self .assertIsInstance (exporter ._session , Session )
128
+ self .assertIn ("User-Agent" , exporter ._session .headers )
129
+ self .assertEqual (
130
+ exporter ._session .headers .get ("Content-Type" ),
131
+ "application/x-protobuf" ,
132
+ )
133
+ self .assertEqual (
134
+ exporter ._session .headers .get ("User-Agent" ),
135
+ "OTel-OTLP-Exporter-Python/" + __version__ ,
136
+ )
127
137
128
138
@patch .dict (
129
139
"os.environ" ,
You can’t perform that action at this time.
0 commit comments