Skip to content

Commit

Permalink
Default otlp-proto-grpc exporter to secure, let https endpoint superc…
Browse files Browse the repository at this point in the history
…ede insecure
  • Loading branch information
areveny committed Jan 2, 2022
1 parent d432153 commit b6f07af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,10 @@ def __init__(

parsed_url = urlparse(endpoint)

if insecure is None:
if parsed_url.scheme == "https":
insecure = False
else:
insecure = True
if insecure and parsed_url.scheme != "https":
insecure = True
else:
insecure = False

if parsed_url.netloc:
endpoint = parsed_url.netloc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ def __init__(
timeout: Optional[int] = None,
compression: Optional[Compression] = None,
):
if (
not insecure
and environ.get(OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE) is not None
):
if environ.get(OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE) is not None:
credentials = _get_credentials(
credentials, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,35 @@ def test_otlp_exporter_endpoint(self, mock_secure, mock_insecure):
(
"http://localhost:4317",
None,
mock_insecure,
mock_secure, # Default secure
),
(
"localhost:4317",
None,
mock_secure, # Default secure
),
(
"http://localhost:4317",
True,
mock_insecure,
),
(
"localhost:4317",
True,
mock_insecure,
),
(
"http://localhost:4317",
False,
mock_secure,
),
(
"localhost:4317",
False,
mock_secure,
),
(
"https://localhost:4317",
False,
mock_secure,
),
Expand All @@ -312,7 +332,7 @@ def test_otlp_exporter_endpoint(self, mock_secure, mock_insecure):
(
"https://localhost:4317",
True,
mock_insecure,
mock_secure, # https scheme overrides explicit insecure
),
]
for endpoint, insecure, mock_method in endpoints:
Expand Down
10 changes: 5 additions & 5 deletions opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,18 @@
.. envvar:: OTEL_EXPORTER_OTLP_ENDPOINT
The :envvar:`OTEL_EXPORTER_OTLP_ENDPOINT` target to which the exporter is going to send spans or metrics.
The endpoint MUST be a valid URL with scheme (http or https) and host, and MAY contain a port and path.
A scheme of https indicates a secure connection.
Default: "https://localhost:4317"
The endpoint MUST be a valid URL host, and MAY contain a scheme (http or https), port and path.
A scheme of https indicates a secure connection and takes precedence over the `insecure` configuration setting.
Default: "http://localhost:4317"
"""

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"
"""
.. envvar:: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
The :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` target to which the span exporter is going to send spans.
The endpoint MUST be a valid URL with scheme (http or https) and host, and MAY contain a port and path.
A scheme of https indicates a secure connection.
The endpoint MUST be a valid URL host, and MAY contain a scheme (http or https), port and path.
A scheme of https indicates a secure connection and takes precedence over the `insecure` configuration setting.
"""

OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"
Expand Down

0 comments on commit b6f07af

Please sign in to comment.