From 64c04f0c282117568170011836916eaebda256b4 Mon Sep 17 00:00:00 2001 From: sreejitkar Date: Mon, 20 Mar 2023 23:35:11 +0530 Subject: [PATCH] Modified all OTLPExporters with correct type signatures and resolved header concatenation issue --- .../exporter/otlp/proto/grpc/_log_exporter/__init__.py | 7 +++++-- .../opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- .../exporter/otlp/proto/grpc/metric_exporter/__init__.py | 7 +++++-- .../exporter/otlp/proto/grpc/trace_exporter/__init__.py | 8 ++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py index f7cbadfec8b..887f9d8b2c2 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py @@ -12,7 +12,8 @@ # limitations under the License. from os import environ -from typing import Optional, Sequence +from typing import Dict, Optional, Tuple, Union, Sequence +from typing import Sequence as TypingSequence from grpc import ChannelCredentials, Compression from opentelemetry.exporter.otlp.proto.grpc.exporter import ( OTLPExporterMixin, @@ -60,7 +61,9 @@ def __init__( endpoint: Optional[str] = None, insecure: Optional[bool] = None, credentials: Optional[ChannelCredentials] = None, - headers: Optional[Sequence] = None, + headers: Optional[ + Union[TypingSequence[Tuple[str, str]], Dict[str, str], str] + ] = None, timeout: Optional[int] = None, compression: Optional[Compression] = None, ): 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 7a56120014c..496fe365f86 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 @@ -256,7 +256,7 @@ def __init__( if self._headers is None: self._headers = tuple(_OTLP_GRPC_HEADERS) else: - self._headers = self._headers + tuple(_OTLP_GRPC_HEADERS) + self._headers = tuple(self._headers) + tuple(_OTLP_GRPC_HEADERS) self._timeout = timeout or int( environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 10) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py index 8abb381cce8..ac17f16d221 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py @@ -14,7 +14,8 @@ import dataclasses from logging import getLogger from os import environ -from typing import Dict, Iterable, List, Optional, Sequence +from typing import Dict, Iterable, List, Optional, Tuple, Union +from typing import Sequence as TypingSequence from grpc import ChannelCredentials, Compression from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.exporter.otlp.proto.grpc.exporter import ( @@ -87,7 +88,9 @@ def __init__( endpoint: Optional[str] = None, insecure: Optional[bool] = None, credentials: Optional[ChannelCredentials] = None, - headers: Optional[Sequence] = None, + headers: Optional[ + Union[TypingSequence[Tuple[str, str]], Dict[str, str], str] + ] = None, timeout: Optional[int] = None, compression: Optional[Compression] = None, preferred_temporality: Dict[type, AggregationTemporality] = None, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py index 0203c00ec36..cfabe3ffce2 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py @@ -15,7 +15,9 @@ import logging from os import environ -from typing import Optional, Sequence +from typing import Dict, Optional, Sequence, Tuple, Union +from typing import Sequence as TypingSequence + from grpc import ChannelCredentials, Compression @@ -80,7 +82,9 @@ def __init__( endpoint: Optional[str] = None, insecure: Optional[bool] = None, credentials: Optional[ChannelCredentials] = None, - headers: Optional[Sequence] = None, + headers: Optional[ + Union[TypingSequence[Tuple[str, str]], Dict[str, str], str] + ] = None, timeout: Optional[int] = None, compression: Optional[Compression] = None, ):