Skip to content

Commit

Permalink
OTLP exporter: Handle error case when no credentials supplied (#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan25 authored Nov 18, 2020
1 parent d556b90 commit a085c10
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions exporter/opentelemetry-exporter-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

Released 2020-11-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
trace.set_tracer_provider(TracerProvider(resource=resource)))
tracer = trace.get_tracer(__name__)
otlp_exporter = OTLPSpanExporter(endpoint="localhost:55680")
otlp_exporter = OTLPSpanExporter(endpoint="localhost:55680", insecure=True)
span_processor = BatchExportSpanProcessor(otlp_exporter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,23 @@ def __init__(
self._client = self._stub(
insecure_channel(endpoint, compression=compression_algorithm)
)
else:
credentials = credentials or _load_credential_from_file(
Configuration().EXPORTER_OTLP_CERTIFICATE
)
self._client = self._stub(
secure_channel(
endpoint, credentials, compression=compression_algorithm
)
return

# secure mode
if (
credentials is None
and Configuration().EXPORTER_OTLP_CERTIFICATE is None
):
raise ValueError("No credentials set in secure mode.")

credentials = credentials or _load_credential_from_file(
Configuration().EXPORTER_OTLP_CERTIFICATE
)
self._client = self._stub(
secure_channel(
endpoint, credentials, compression=compression_algorithm
)
)

@abstractmethod
def _translate_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def test_env_variables(self, mock_exporter_mixin):
self.assertIsNotNone(kwargs["credentials"])
self.assertIsInstance(kwargs["credentials"], ChannelCredentials)

def test_no_credentials_error(self):
with self.assertRaises(ValueError):
OTLPMetricsExporter()

@patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
def test_translate_metrics(self, mock_time_ns):
# pylint: disable=no-member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def test_env_variables(self, mock_exporter_mixin):
self.assertIsNotNone(kwargs["credentials"])
self.assertIsInstance(kwargs["credentials"], ChannelCredentials)

def test_no_credentials_error(self):
with self.assertRaises(ValueError):
OTLPSpanExporter()

@patch("opentelemetry.exporter.otlp.exporter.expo")
@patch("opentelemetry.exporter.otlp.exporter.sleep")
def test_unavailable(self, mock_sleep, mock_expo):
Expand Down

0 comments on commit a085c10

Please sign in to comment.