From 9bbf9cf84cb90d0d10af48cd5e8905a7ed658ac6 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Wed, 28 Oct 2026 16:47:28 +0300 Subject: [PATCH] fix: skip the unencrypted-OTLP warning for https gRPC endpoints The gRPC exporter forces TLS for an https endpoint whatever insecure says, so the warning told users their telemetry was unencrypted when it was not. Fixes #333. --- lite_bootstrap/instruments/opentelemetry_instrument.py | 3 +++ tests/instruments/test_opentelemetry_instrument.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lite_bootstrap/instruments/opentelemetry_instrument.py b/lite_bootstrap/instruments/opentelemetry_instrument.py index 98cd858..c19348e 100644 --- a/lite_bootstrap/instruments/opentelemetry_instrument.py +++ b/lite_bootstrap/instruments/opentelemetry_instrument.py @@ -114,6 +114,9 @@ def _parse_remote_insecure_host(self, endpoint: str | None) -> str | None: if "://" not in raw: raw = f"//{raw}" parsed = urllib.parse.urlparse(raw) + # The gRPC exporter forces TLS for https whatever insecure says. + if parsed.scheme == "https": + return None host = (parsed.hostname or "").lower() if host in _LOCAL_HOSTS: return None diff --git a/tests/instruments/test_opentelemetry_instrument.py b/tests/instruments/test_opentelemetry_instrument.py index 6b0c72a..76d8896 100644 --- a/tests/instruments/test_opentelemetry_instrument.py +++ b/tests/instruments/test_opentelemetry_instrument.py @@ -231,6 +231,13 @@ def test_opentelemetry_config_no_warning_for_local_endpoints(endpoint: str) -> N OpenTelemetryConfig(opentelemetry_endpoint=endpoint, opentelemetry_insecure=True) +@pytest.mark.parametrize("endpoint", ["https://collector.example.com:4317", "HTTPS://collector.example.com:4317"]) +def test_opentelemetry_config_no_warning_for_https_endpoints(endpoint: str) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("error") + OpenTelemetryConfig(opentelemetry_endpoint=endpoint, opentelemetry_metrics_endpoint=endpoint) + + @pytest.mark.parametrize( "endpoint", [