Skip to content

Commit a085c10

Browse files
authored
OTLP exporter: Handle error case when no credentials supplied (open-telemetry#1366)
1 parent d556b90 commit a085c10

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

exporter/opentelemetry-exporter-otlp/CHANGELOG.md

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

55
- Add Gzip compression for exporter
66
([#1141](https://github.com/open-telemetry/opentelemetry-python/pull/1141))
7+
- OTLP exporter: Handle error case when no credentials supplied
8+
([#1366](https://github.com/open-telemetry/opentelemetry-python/pull/1366))
79
## Version 0.15b0
810

911
Released 2020-11-02

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
trace.set_tracer_provider(TracerProvider(resource=resource)))
5454
tracer = trace.get_tracer(__name__)
5555
56-
otlp_exporter = OTLPSpanExporter(endpoint="localhost:55680")
56+
otlp_exporter = OTLPSpanExporter(endpoint="localhost:55680", insecure=True)
5757
5858
span_processor = BatchExportSpanProcessor(otlp_exporter)
5959

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,23 @@ def __init__(
201201
self._client = self._stub(
202202
insecure_channel(endpoint, compression=compression_algorithm)
203203
)
204-
else:
205-
credentials = credentials or _load_credential_from_file(
206-
Configuration().EXPORTER_OTLP_CERTIFICATE
207-
)
208-
self._client = self._stub(
209-
secure_channel(
210-
endpoint, credentials, compression=compression_algorithm
211-
)
204+
return
205+
206+
# secure mode
207+
if (
208+
credentials is None
209+
and Configuration().EXPORTER_OTLP_CERTIFICATE is None
210+
):
211+
raise ValueError("No credentials set in secure mode.")
212+
213+
credentials = credentials or _load_credential_from_file(
214+
Configuration().EXPORTER_OTLP_CERTIFICATE
215+
)
216+
self._client = self._stub(
217+
secure_channel(
218+
endpoint, credentials, compression=compression_algorithm
212219
)
220+
)
213221

214222
@abstractmethod
215223
def _translate_data(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def test_env_variables(self, mock_exporter_mixin):
9191
self.assertIsNotNone(kwargs["credentials"])
9292
self.assertIsInstance(kwargs["credentials"], ChannelCredentials)
9393

94+
def test_no_credentials_error(self):
95+
with self.assertRaises(ValueError):
96+
OTLPMetricsExporter()
97+
9498
@patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
9599
def test_translate_metrics(self, mock_time_ns):
96100
# pylint: disable=no-member

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ def test_env_variables(self, mock_exporter_mixin):
183183
self.assertIsNotNone(kwargs["credentials"])
184184
self.assertIsInstance(kwargs["credentials"], ChannelCredentials)
185185

186+
def test_no_credentials_error(self):
187+
with self.assertRaises(ValueError):
188+
OTLPSpanExporter()
189+
186190
@patch("opentelemetry.exporter.otlp.exporter.expo")
187191
@patch("opentelemetry.exporter.otlp.exporter.sleep")
188192
def test_unavailable(self, mock_sleep, mock_expo):

0 commit comments

Comments
 (0)