From 0691243c78fc070b7fb710c3d4760d0e68df6e00 Mon Sep 17 00:00:00 2001 From: Angelo Tessaro Date: Sun, 18 Feb 2024 17:41:22 -0300 Subject: [PATCH] Add auth parameter to enable Custom HTTP authentication like AWS Sigv4 --- .../exporter/prometheus_remote_write/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py index 652e5eae8d..d1d849fa61 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py @@ -66,6 +66,7 @@ class PrometheusRemoteWriteMetricsExporter(MetricExporter): timeout: timeout for remote write requests in seconds, defaults to 30 (Optional) proxies: dict mapping request proxy protocols to proxy urls (Optional) tls_config: configuration for remote write TLS settings (Optional) + auth: auth tuple or callable to enable Basic/Digest/Custom HTTP Auth (Optional) """ def __init__( @@ -79,6 +80,7 @@ def __init__( resources_as_labels: bool = True, preferred_temporality: Dict[type, AggregationTemporality] = None, preferred_aggregation: Dict = None, + auth = None, ): self.endpoint = endpoint self.basic_auth = basic_auth @@ -87,6 +89,7 @@ def __init__( self.tls_config = tls_config self.proxies = proxies self.resources_as_labels = resources_as_labels + self.auth = auth if not preferred_temporality: preferred_temporality = { @@ -181,6 +184,14 @@ def headers(self): def headers(self, headers: Dict): self._headers = headers + @property + def auth(self): + return self._auth + + @auth.setter + def auth(self, auth): + self._auth = auth + def export( self, metrics_data: MetricsData, @@ -370,6 +381,8 @@ def _send_message( auth = None if self.basic_auth: auth = (self.basic_auth["username"], self.basic_auth["password"]) + elif self.auth: + auth = self.auth cert = None verify = True