Skip to content

Commit 0553378

Browse files
committed
opentelemetry-exporter-otlp-proto-grpc: set user agent properly
It looks like metadata is ignored and instead we should set the grpc.primary_user_agent channel option instead. User-agent will change from: grpc-python/1.71.0 grpc-c/46.0.0 (linux; chttp2) to: OTel-OTLP-Exporter-Python/1.34.1 grpc-python/1.71.0 grpc-c/46.0.0 (linux; chttp2)
1 parent 2a0282c commit 0553378

File tree

2 files changed

+12
-6
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc

2 files changed

+12
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@
7373
from .version import __version__
7474

7575
_USER_AGENT_HEADER_VALUE = "OTel-OTLP-Exporter-Python/" + __version__
76-
_OTLP_GRPC_HEADERS = [("user-agent", _USER_AGENT_HEADER_VALUE)]
76+
_OTLP_GRPC_CHANNEL_OPTIONS = [
77+
("grpc.primary_user_agent", _USER_AGENT_HEADER_VALUE)
78+
]

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
_get_resource_data,
5252
)
5353
from opentelemetry.exporter.otlp.proto.grpc import (
54-
_OTLP_GRPC_HEADERS,
54+
_OTLP_GRPC_CHANNEL_OPTIONS,
5555
)
5656
from opentelemetry.proto.common.v1.common_pb2 import ( # noqa: F401
5757
AnyValue,
@@ -196,6 +196,7 @@ class OTLPExporterMixin(
196196
headers: Headers to send when exporting
197197
timeout: Backend request timeout in seconds
198198
compression: gRPC compression method to use
199+
channel_options: gRPC channel options
199200
"""
200201

201202
def __init__(
@@ -208,6 +209,7 @@ def __init__(
208209
] = None,
209210
timeout: Optional[float] = None,
210211
compression: Optional[Compression] = None,
212+
channel_options: Optional[TypingSequence[Tuple[str, str]]] = None,
211213
):
212214
super().__init__()
213215

@@ -238,10 +240,10 @@ def __init__(
238240
self._headers = tuple(temp_headers.items())
239241
elif isinstance(self._headers, dict):
240242
self._headers = tuple(self._headers.items())
241-
if self._headers is None:
242-
self._headers = tuple(_OTLP_GRPC_HEADERS)
243-
else:
244-
self._headers = tuple(self._headers) + tuple(_OTLP_GRPC_HEADERS)
243+
244+
self._channel_options = channel_options or tuple(
245+
_OTLP_GRPC_CHANNEL_OPTIONS
246+
)
245247

246248
self._timeout = timeout or float(
247249
environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 10)
@@ -258,6 +260,7 @@ def __init__(
258260
self._channel = insecure_channel(
259261
self._endpoint,
260262
compression=compression,
263+
options=channel_options,
261264
)
262265
else:
263266
credentials = _get_credentials(
@@ -270,6 +273,7 @@ def __init__(
270273
self._endpoint,
271274
credentials,
272275
compression=compression,
276+
options=channel_options,
273277
)
274278
self._client = self._stub(self._channel)
275279

0 commit comments

Comments
 (0)