Skip to content

Commit 8f312c4

Browse files
Fix User-Agent header value for OTLP exporters (#3128)
* Update values as required for issue * add CHANGED_FILES link * update changelog * update test to validate setting * update only oltp exporter * update grpc exporter * Update CHANGELOG.md Co-authored-by: Srikanth Chekuri <[email protected]> * remove CHANGED_FILES# * update location of imports for linting Co-authored-by: Srikanth Chekuri <[email protected]>
1 parent ce27da9 commit 8f312c4

File tree

8 files changed

+21
-10
lines changed

8 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
([3124](https://github.com/open-telemetry/opentelemetry-python/pull/3124))
1313
- Add db metric name to semantic conventions
1414
([#3115](https://github.com/open-telemetry/opentelemetry-python/pull/3115))
15-
15+
- Fix User-Agent header value for OTLP exporters to conform to RFC7231 & RFC7230
16+
([#3128](https://github.com/open-telemetry/opentelemetry-python/pull/3128))
1617
- Fix validation of baggage values
1718
([#3058](https://github.com/open-telemetry/opentelemetry-python/pull/3058))
1819

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@
7171
"""
7272
from .version import __version__
7373

74-
_USER_AGENT_HEADER_VALUE = "OTel OTLP Exporter Python/" + __version__
74+
_USER_AGENT_HEADER_VALUE = "OTel-OTLP-Exporter-Python/" + __version__
7575
_OTLP_GRPC_HEADERS = [("user-agent", _USER_AGENT_HEADER_VALUE)]

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_otlp_headers_from_env(self):
289289
# pylint: disable=protected-access
290290
self.assertEqual(
291291
self.exporter._headers,
292-
(("user-agent", "OTel OTLP Exporter Python/" + __version__),),
292+
(("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),),
293293
)
294294

295295
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._expo")

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
418418
(
419419
("key1", "value1"),
420420
("key2", "VALUE=2"),
421-
("user-agent", "OTel OTLP Exporter Python/" + __version__),
421+
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
422422
),
423423
)
424424
exporter = OTLPMetricExporter(
@@ -430,7 +430,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
430430
(
431431
("key3", "value3"),
432432
("key4", "value4"),
433-
("user-agent", "OTel OTLP Exporter Python/" + __version__),
433+
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
434434
),
435435
)
436436

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
281281
(
282282
("key1", "value1"),
283283
("key2", "VALUE=2"),
284-
("user-agent", "OTel OTLP Exporter Python/" + __version__),
284+
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
285285
),
286286
)
287287
exporter = OTLPSpanExporter(
@@ -293,7 +293,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
293293
(
294294
("key3", "value3"),
295295
("key4", "value4"),
296-
("user-agent", "OTel OTLP Exporter Python/" + __version__),
296+
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
297297
),
298298
)
299299
exporter = OTLPSpanExporter(
@@ -305,7 +305,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
305305
(
306306
("key5", "value5"),
307307
("key6", "value6"),
308-
("user-agent", "OTel OTLP Exporter Python/" + __version__),
308+
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
309309
),
310310
)
311311

@@ -454,7 +454,7 @@ def test_otlp_headers(self, mock_ssl_channel, mock_secure):
454454
# This ensures that there is no other header than standard user-agent.
455455
self.assertEqual(
456456
exporter._headers,
457-
(("user-agent", "OTel OTLP Exporter Python/" + __version__),),
457+
(("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),),
458458
)
459459

460460
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.backoff")

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
_OTLP_HTTP_HEADERS = {
7878
"Content-Type": "application/x-protobuf",
79-
"User-Agent": "OTel OTLP Exporter Python/" + __version__,
79+
"User-Agent": "OTel-OTLP-Exporter-Python/" + __version__,
8080
}
8181

8282

exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
_encode_value,
3939
_ProtobufEncoder,
4040
)
41+
from opentelemetry.exporter.otlp.proto.http.version import __version__
4142
from opentelemetry.proto.collector.logs.v1.logs_service_pb2 import (
4243
ExportLogsServiceRequest,
4344
)
@@ -96,6 +97,10 @@ def test_constructor_default(self):
9697
exporter._session.headers.get("Content-Type"),
9798
"application/x-protobuf",
9899
)
100+
self.assertEqual(
101+
exporter._session.headers.get("User-Agent"),
102+
"OTel-OTLP-Exporter-Python/" + __version__,
103+
)
99104

100105
@patch.dict(
101106
"os.environ",

exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
OTLPSpanExporter,
2929
_is_backoff_v2,
3030
)
31+
from opentelemetry.exporter.otlp.proto.http.version import __version__
3132
from opentelemetry.sdk.environment_variables import (
3233
OTEL_EXPORTER_OTLP_CERTIFICATE,
3334
OTEL_EXPORTER_OTLP_COMPRESSION,
@@ -67,6 +68,10 @@ def test_constructor_default(self):
6768
exporter._session.headers.get("Content-Type"),
6869
"application/x-protobuf",
6970
)
71+
self.assertEqual(
72+
exporter._session.headers.get("User-Agent"),
73+
"OTel-OTLP-Exporter-Python/" + __version__,
74+
)
7075

7176
@patch.dict(
7277
"os.environ",

0 commit comments

Comments
 (0)