Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix User-Agent header value for OTLP exporters #3128

Merged
Merged
7 changes: 7 additions & 0 deletions CHANGED_FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/__init__.py
exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py
exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py
exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py
exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py
exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py
keithkroeger marked this conversation as resolved.
Show resolved Hide resolved
exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add db metric name to semantic conventions
([#3115](https://github.com/open-telemetry/opentelemetry-python/pull/3115))

- Remove spaces from example exporter User-Agent header to conform to RFC7231 & RFC7230.
keithkroeger marked this conversation as resolved.
Show resolved Hide resolved

## Version 1.15.0/0.36b0 (2022-12-09)

- Regenerate opentelemetry-proto to be compatible with protobuf 3 and 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@
"""
from .version import __version__

_USER_AGENT_HEADER_VALUE = "OTel OTLP Exporter Python/" + __version__
_USER_AGENT_HEADER_VALUE = "OTel-OTLP-Exporter-Python/" + __version__
_OTLP_GRPC_HEADERS = [("user-agent", _USER_AGENT_HEADER_VALUE)]
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_otlp_headers_from_env(self):
# pylint: disable=protected-access
self.assertEqual(
self.exporter._headers,
(("user-agent", "OTel OTLP Exporter Python/" + __version__),),
(("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),),
)

@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._expo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
(
("key1", "value1"),
("key2", "VALUE=2"),
("user-agent", "OTel OTLP Exporter Python/" + __version__),
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
),
)
exporter = OTLPMetricExporter(
Expand All @@ -430,7 +430,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
(
("key3", "value3"),
("key4", "value4"),
("user-agent", "OTel OTLP Exporter Python/" + __version__),
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
(
("key1", "value1"),
("key2", "VALUE=2"),
("user-agent", "OTel OTLP Exporter Python/" + __version__),
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
),
)
exporter = OTLPSpanExporter(
Expand All @@ -293,7 +293,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
(
("key3", "value3"),
("key4", "value4"),
("user-agent", "OTel OTLP Exporter Python/" + __version__),
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
),
)
exporter = OTLPSpanExporter(
Expand All @@ -305,7 +305,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure):
(
("key5", "value5"),
("key6", "value6"),
("user-agent", "OTel OTLP Exporter Python/" + __version__),
("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),
),
)

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

@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.backoff")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import responses

from opentelemetry._logs import SeverityNumber
from opentelemetry.exporter.otlp.proto.http.version import __version__
from opentelemetry.exporter.otlp.proto.http import Compression
from opentelemetry.exporter.otlp.proto.http._log_exporter import (
DEFAULT_COMPRESSION,
Expand Down Expand Up @@ -96,6 +97,10 @@ def test_constructor_default(self):
exporter._session.headers.get("Content-Type"),
"application/x-protobuf",
)
self.assertEqual(
exporter._session.headers.get("User-Agent"),
"OTel-OTLP-Exporter-Python/" + __version__,
)

@patch.dict(
"os.environ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import requests
import responses

from opentelemetry.exporter.otlp.proto.http.version import __version__
from opentelemetry.exporter.otlp.proto.http import Compression
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
DEFAULT_COMPRESSION,
Expand Down Expand Up @@ -67,6 +68,10 @@ def test_constructor_default(self):
exporter._session.headers.get("Content-Type"),
"application/x-protobuf",
)
self.assertEqual(
exporter._session.headers.get("User-Agent"),
"OTel-OTLP-Exporter-Python/" + __version__,
)

@patch.dict(
"os.environ",
Expand Down