diff --git a/src/honeycomb/opentelemetry/options.py b/src/honeycomb/opentelemetry/options.py index 4b6ec0b..e7e4d71 100644 --- a/src/honeycomb/opentelemetry/options.py +++ b/src/honeycomb/opentelemetry/options.py @@ -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 @@ -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 diff --git a/tests/test_options.py b/tests/test_options.py index 8eeaab8..7ea5cd4 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -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 @@ -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)