Skip to content

Commit 00578e3

Browse files
author
alrex
authored
OTLP exporter use grpc runtime cert if not set (open-telemetry#1430)
1 parent 50f5c6c commit 00578e3

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

exporter/opentelemetry-exporter-otlp/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## Version 0.16b1
6+
7+
Released 2020-11-26
8+
59
- Add meter reference to observers
610
([#1425](https://github.com/open-telemetry/opentelemetry-python/pull/1425))
711

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ def __init__(
208208
credentials is None
209209
and Configuration().EXPORTER_OTLP_CERTIFICATE is None
210210
):
211-
raise ValueError("No credentials set in secure mode.")
212-
213-
credentials = credentials or _load_credential_from_file(
214-
Configuration().EXPORTER_OTLP_CERTIFICATE
215-
)
211+
# use the default location chosen by gRPC runtime
212+
credentials = ssl_channel_credentials()
213+
else:
214+
credentials = credentials or _load_credential_from_file(
215+
Configuration().EXPORTER_OTLP_CERTIFICATE
216+
)
216217
self._client = self._stub(
217218
secure_channel(
218219
endpoint, credentials, compression=compression_algorithm

exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,17 @@ def test_env_variables(self, mock_exporter_mixin):
9090
self.assertIsNotNone(kwargs["credentials"])
9191
self.assertIsInstance(kwargs["credentials"], ChannelCredentials)
9292

93-
def test_no_credentials_error(self):
94-
with self.assertRaises(ValueError):
95-
OTLPMetricsExporter()
93+
@patch("opentelemetry.exporter.otlp.exporter.ssl_channel_credentials")
94+
@patch("opentelemetry.exporter.otlp.exporter.secure_channel")
95+
@patch(
96+
"opentelemetry.exporter.otlp.metrics_exporter.OTLPMetricsExporter._stub"
97+
)
98+
# pylint: disable=unused-argument
99+
def test_no_credentials_error(
100+
self, mock_ssl_channel, mock_secure, mock_stub
101+
):
102+
OTLPMetricsExporter(insecure=False)
103+
self.assertTrue(mock_ssl_channel.called)
96104

97105
@patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
98106
def test_translate_counter_export_record(self, mock_time_ns):

exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ def test_env_variables(self, mock_exporter_mixin):
187187
self.assertIsNotNone(kwargs["credentials"])
188188
self.assertIsInstance(kwargs["credentials"], ChannelCredentials)
189189

190-
def test_no_credentials_error(self):
191-
with self.assertRaises(ValueError):
192-
OTLPSpanExporter()
190+
@patch("opentelemetry.exporter.otlp.exporter.ssl_channel_credentials")
191+
@patch("opentelemetry.exporter.otlp.exporter.secure_channel")
192+
@patch("opentelemetry.exporter.otlp.trace_exporter.OTLPSpanExporter._stub")
193+
# pylint: disable=unused-argument
194+
def test_no_credentials_error(
195+
self, mock_ssl_channel, mock_secure, mock_stub
196+
):
197+
OTLPSpanExporter(insecure=False)
198+
self.assertTrue(mock_ssl_channel.called)
193199

194200
@patch("opentelemetry.exporter.otlp.exporter.expo")
195201
@patch("opentelemetry.exporter.otlp.exporter.sleep")

0 commit comments

Comments
 (0)