Skip to content

Commit

Permalink
Remove insecure param from exporters constructor and OTEL_EXPORTER_*_…
Browse files Browse the repository at this point in the history
… INSECURE env var (open-telemetry#1682)
  • Loading branch information
srikanthccv authored and Alex Boten committed Mar 16, 2021
1 parent 2417a42 commit 9664f9f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 65 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed
- Removed unused `get_hexadecimal_trace_id` and `get_hexadecimal_span_id` methods.
([#1675])(https://github.com/open-telemetry/opentelemetry-python/pull/1675)
([#1675](https://github.com/open-telemetry/opentelemetry-python/pull/1675))
- Remove `OTEL_EXPORTER_*_ INSECURE` env var
([#1682](https://github.com/open-telemetry/opentelemetry-python/pull/1682))

## [0.18b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.18b0) - 2021-02-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,10 @@

from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_JAEGER_CERTIFICATE,
OTEL_EXPORTER_JAEGER_INSECURE,
)

logger = logging.getLogger(__name__)

DEFAULT_INSECURE = False


def _get_insecure(param):
if param is not None:
return param
insecure_env = environ.get(OTEL_EXPORTER_JAEGER_INSECURE)
if insecure_env is not None:
return insecure_env.lower() == "true"
return DEFAULT_INSECURE


def _load_credential_from_file(path) -> ChannelCredentials:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_INSECURE`
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_HEADERS`
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION`
- :envvar:`OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE`
- :envvar:`OTEL_EXPORTER_OTLP_TIMEOUT`
- :envvar:`OTEL_EXPORTER_OTLP_PROTOCOL`
- :envvar:`OTEL_EXPORTER_OTLP_INSECURE`
- :envvar:`OTEL_EXPORTER_OTLP_HEADERS`
- :envvar:`OTEL_EXPORTER_OTLP_ENDPOINT`
- :envvar:`OTEL_EXPORTER_OTLP_COMPRESSION`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
OTEL_EXPORTER_OTLP_COMPRESSION,
OTEL_EXPORTER_OTLP_ENDPOINT,
OTEL_EXPORTER_OTLP_HEADERS,
OTEL_EXPORTER_OTLP_INSECURE,
OTEL_EXPORTER_OTLP_TIMEOUT,
)
from opentelemetry.sdk.resources import Resource as SDKResource
Expand Down Expand Up @@ -159,6 +158,15 @@ def _load_credential_from_file(filepath) -> ChannelCredentials:
return None


def _get_credentials(creds, environ_key):
if creds is not None:
return creds
creds_env = environ.get(environ_key)
if creds_env:
return _load_credential_from_file(creds_env)
return ssl_channel_credentials()


# pylint: disable=no-member
class OTLPExporterMixin(
ABC, Generic[SDKDataT, ExportServiceRequestT, ExportResultT]
Expand All @@ -185,26 +193,17 @@ def __init__(
):
super().__init__()

endpoint = (
endpoint
or environ.get(OTEL_EXPORTER_OTLP_ENDPOINT)
or "localhost:4317"
endpoint = endpoint or environ.get(
OTEL_EXPORTER_OTLP_ENDPOINT, "localhost:4317"
)

if insecure is None:
insecure = environ.get(OTEL_EXPORTER_OTLP_INSECURE)
if insecure is None:
insecure = False

self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS)
if isinstance(self._headers, str):
self._headers = tuple(
tuple(item.split("=")) for item in self._headers.split(",")
)
self._timeout = (
timeout
or int(environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 0))
or 10 # default: 10 seconds
self._timeout = timeout or int(
environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 10)
)
self._collector_span_kwargs = None

Expand All @@ -218,22 +217,13 @@ def __init__(
self._client = self._stub(
insecure_channel(endpoint, compression=compression)
)
return

# secure mode
if (
credentials is None
and environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE) is None
):
# use the default location chosen by gRPC runtime
credentials = ssl_channel_credentials()
else:
credentials = credentials or _load_credential_from_file(
environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE)
credentials = _get_credentials(
credentials, OTEL_EXPORTER_OTLP_CERTIFICATE
)
self._client = self._stub(
secure_channel(endpoint, credentials, compression=compression)
)
self._client = self._stub(
secure_channel(endpoint, credentials, compression=compression)
)

@abstractmethod
def _translate_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from opentelemetry.exporter.otlp.exporter import (
OTLPExporterMixin,
_load_credential_from_file,
_get_credentials,
_translate_key_values,
environ_to_compression,
get_resource_data,
Expand All @@ -44,7 +44,6 @@
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION,
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
OTEL_EXPORTER_OTLP_TRACES_HEADERS,
OTEL_EXPORTER_OTLP_TRACES_INSECURE,
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
)
from opentelemetry.sdk.trace import Span as ReadableSpan
Expand Down Expand Up @@ -85,15 +84,12 @@ def __init__(
timeout: Optional[int] = None,
compression: Optional[Compression] = None,
):
if insecure is None:
insecure = environ.get(OTEL_EXPORTER_OTLP_TRACES_INSECURE)

if (
not insecure
and environ.get(OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE) is not None
):
credentials = credentials or _load_credential_from_file(
environ.get(OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE)
credentials = _get_credentials(
credentials, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE
)

environ_timeout = environ.get(OTEL_EXPORTER_OTLP_TRACES_TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@
.. envvar:: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT
"""

OTEL_EXPORTER_JAEGER_INSECURE = "OTEL_EXPORTER_JAEGER_INSECURE"
"""
.. envvar:: OTEL_EXPORTER_JAEGER_INSECURE
"""

OTEL_EXPORTER_JAEGER_CERTIFICATE = "OTEL_EXPORTER_JAEGER_CERTIFICATE"
"""
.. envvar:: OTEL_EXPORTER_JAEGER_CERTIFICATE
Expand All @@ -215,13 +210,3 @@
"""
.. envvar:: OTEL_EXPORTER_JAEGER_AGENT_SPLIT_OVERSIZED_BATCHES
"""

OTEL_EXPORTER_OTLP_INSECURE = "OTEL_EXPORTER_OTLP_INSECURE"
"""
.. envvar:: OTEL_EXPORTER_OTLP_INSECURE
"""

OTEL_EXPORTER_OTLP_TRACES_INSECURE = "OTEL_EXPORTER_OTLP_TRACES_INSECURE"
"""
.. envvar:: OTEL_EXPORTER_OTLP_TRACES_INSECURE
"""

0 comments on commit 9664f9f

Please sign in to comment.