Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: Don’t append OTLP signal paths if already present #156

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/honeycomb/opentelemetry/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
EXPORTER_PROTOCOL_GRPC = "grpc"
EXPORTER_PROTOCOL_HTTP_PROTO = "http/protobuf"

TRACES_HTTP_PATH = "v1/traces"
METRICS_HTTP_PATH = "v1/metrics"

exporter_protocols = {
EXPORTER_PROTOCOL_GRPC,
EXPORTER_PROTOCOL_HTTP_PROTO
Expand Down Expand Up @@ -155,26 +158,28 @@ def parse_int(environment_variable: str,
def _append_traces_path(protocol: str, endpoint: str) -> str:
"""
Appends the OTLP traces HTTP path '/v1/traces' to the endpoint if the
protocol is http/protobuf.
protocol is http/protobuf and it doesn't already exist.

Returns:
string: the endpoint, optionally appended with traces path
"""
if endpoint and protocol == "http/protobuf":
return "/".join([endpoint.strip("/"), "v1/traces"])
if endpoint and protocol == "http/protobuf" \
and not endpoint.strip("/").endswith(TRACES_HTTP_PATH):
return "/".join([endpoint.strip("/"), TRACES_HTTP_PATH])
return endpoint


def _append_metrics_path(protocol: str, endpoint: str) -> str:
"""
Appends the OTLP metrics HTTP path '/v1/metrics' to the endpoint if the
protocol is http/protobuf.
protocol is http/protobuf and it doesn't already exist.

Returns:
string: the endpoint, optionally appended with metrics path
"""
if endpoint and protocol == "http/protobuf":
return "/".join([endpoint.strip("/"), "v1/metrics"])
if endpoint and protocol == "http/protobuf" \
and not endpoint.strip("/").endswith(METRICS_HTTP_PATH):
return "/".join([endpoint.strip("/"), METRICS_HTTP_PATH])
return endpoint


Expand Down
20 changes: 20 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,16 @@ def test_get_traces_endpoint_with_http_proto_protocol_returns_correctly_formatte
options = HoneycombOptions(exporter_protocol=protocol)
assert options.get_traces_endpoint() == EXPECTED_ENDPOINT

def test_get_traces_endpoint_with_traces_path_and_http_proto_returns_corretly_formatted_endpoint(monkeypatch):
# http
protocol = EXPORTER_PROTOCOL_HTTP_PROTO

# endpoint already has /v1/traces
endpoint = DEFAULT_API_ENDPOINT + "/v1/traces"

# set endpoint in options
options = HoneycombOptions(exporter_protocol=protocol, endpoint=endpoint)
assert options.get_traces_endpoint() == endpoint

def test_get_metrics_endpoint_with_grpc_protocol_returns_correctly_formatted_endpoint(monkeypatch):
# grpc
Expand Down Expand Up @@ -546,6 +556,16 @@ def test_get_metrics_endpoint_with_http_proto_protocol_returns_correctly_formatt
options = HoneycombOptions(exporter_protocol=protocol)
assert options.get_metrics_endpoint() == EXPECTED_ENDPOINT

def test_get_metrics_endpoint_with_metrics_path_and_http_proto_returns_corretly_formatted_endpoint(monkeypatch):
# http
protocol = EXPORTER_PROTOCOL_HTTP_PROTO

# endpoint already has /v1/metrics
endpoint = DEFAULT_API_ENDPOINT + "/v1/metrics"

# set endpoint in options
options = HoneycombOptions(exporter_protocol=protocol, endpoint=endpoint)
assert options.get_metrics_endpoint() == endpoint

def test_debug_sets_log_level_to_debug():
options = HoneycombOptions(debug=True)
Expand Down