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

bugfix(exporter): set user agent for otlp metrics exporter #4475

Merged
merged 7 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4458](https://github.com/open-telemetry/opentelemetry-python/pull/4458))
- pylint-ci updated python version to 3.13
([#4450](https://github.com/open-telemetry/opentelemetry-python/pull/4450))
- Fix user agent in OTLP HTTP metrics exporter
([#4475](https://github.com/open-telemetry/opentelemetry-python/pull/4475))

## Version 1.30.0/0.51b0 (2025-02-03)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
from opentelemetry.exporter.otlp.proto.common.metrics_encoder import (
encode_metrics,
)
from opentelemetry.exporter.otlp.proto.http import Compression
from opentelemetry.exporter.otlp.proto.http import (
_OTLP_HTTP_HEADERS,
Compression,
)
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( # noqa: F401
ExportMetricsServiceRequest,
)
Expand Down Expand Up @@ -152,9 +155,7 @@ def __init__(
self._compression = compression or _compression_from_env()
self._session = session or requests.Session()
self._session.headers.update(self._headers)
self._session.headers.update(
{"Content-Type": "application/x-protobuf"}
)
self._session.headers.update(_OTLP_HTTP_HEADERS)
if self._compression is not Compression.NoCompression:
self._session.headers.update(
{"Content-Encoding": self._compression.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
DEFAULT_TIMEOUT,
OTLPMetricExporter,
)
from opentelemetry.exporter.otlp.proto.http.version import __version__
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_CERTIFICATE,
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE,
Expand Down Expand Up @@ -124,6 +125,15 @@ def test_constructor_default(self):
self.assertIs(exporter._compression, DEFAULT_COMPRESSION)
self.assertEqual(exporter._headers, {})
self.assertIsInstance(exporter._session, Session)
self.assertIn("User-Agent", exporter._session.headers)
self.assertEqual(
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
Loading