From 1907312ebb0d3e0fea1c56a039ac0c784c4412ec Mon Sep 17 00:00:00 2001 From: Pridhi Arora Date: Tue, 1 Nov 2022 15:28:28 +0530 Subject: [PATCH] Adds user agent string to grpc headers --- CHANGELOG.md | 1 + .../src/opentelemetry/exporter/otlp/proto/grpc/__init__.py | 3 +++ .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2358664bdf4..eb56196b5a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2976](https://github.com/open-telemetry/opentelemetry-python/pull/2976)) - [exporter/opentelemetry-exporter-otlp-proto-http] Add OTLPMetricExporter ([#2891](https://github.com/open-telemetry/opentelemetry-python/pull/2891)) +- `exporter-otlp-proto-grpc`: add user agent string ## [1.13.0-0.34b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.13.0) - 2022-09-26 diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py index 0a33b6325ad..fb32e13070a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py @@ -69,3 +69,6 @@ API --- """ +from .version import __version__ + +_OTLP_GRPC_HEADERS = (('User-Agent', 'OTel OTLP Exporter Python/' + __version__)) \ No newline at end of file diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index 4405bcad68b..21e9ff6e55c 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -54,6 +54,9 @@ from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.util.re import parse_headers from opentelemetry.sdk.metrics.export import MetricsData +from opentelemetry.exporter.otlp.proto.grpc import ( + _OTLP_GRPC_HEADERS, +) logger = getLogger(__name__) SDKDataT = TypeVar("SDKDataT") @@ -239,6 +242,7 @@ def __init__( elif isinstance(self._headers, dict): self._headers = tuple(self._headers.items()) + self._headers = self._headers + _OTLP_GRPC_HEADERS self._timeout = timeout or int( environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 10) )