Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 9bc3f9a

Browse files
maint: Don’t append OTLP signal paths if already present (#156)
## Which problem is this PR solving? If an HTTP endpoint for traces or metrics already includes the signal path (eg /v1/traces or /v1/metrics), the path is added a second time (eg `http://somewhere.com/v1/traces` becomes `http://somewhere.com/v1/traces/v1/traces`). The path should only be added if it doesn't already exist. - Closes #155 ## Short description of the changes - Update options.get_traces_endpoint and options.get_metrics_endpoint to check if the endpoint already ends with the signal path before adding it - Add tests to verify behaviour ## How to verify that this has the expected result You can now use an endpoint with a signal path and the signal path won't be added twice.
1 parent 9f8466f commit 9bc3f9a

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/honeycomb/opentelemetry/options.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
EXPORTER_PROTOCOL_GRPC = "grpc"
7979
EXPORTER_PROTOCOL_HTTP_PROTO = "http/protobuf"
8080

81+
TRACES_HTTP_PATH = "v1/traces"
82+
METRICS_HTTP_PATH = "v1/metrics"
83+
8184
exporter_protocols = {
8285
EXPORTER_PROTOCOL_GRPC,
8386
EXPORTER_PROTOCOL_HTTP_PROTO
@@ -155,26 +158,28 @@ def parse_int(environment_variable: str,
155158
def _append_traces_path(protocol: str, endpoint: str) -> str:
156159
"""
157160
Appends the OTLP traces HTTP path '/v1/traces' to the endpoint if the
158-
protocol is http/protobuf.
161+
protocol is http/protobuf and it doesn't already exist.
159162
160163
Returns:
161164
string: the endpoint, optionally appended with traces path
162165
"""
163-
if endpoint and protocol == "http/protobuf":
164-
return "/".join([endpoint.strip("/"), "v1/traces"])
166+
if endpoint and protocol == "http/protobuf" \
167+
and not endpoint.strip("/").endswith(TRACES_HTTP_PATH):
168+
return "/".join([endpoint.strip("/"), TRACES_HTTP_PATH])
165169
return endpoint
166170

167171

168172
def _append_metrics_path(protocol: str, endpoint: str) -> str:
169173
"""
170174
Appends the OTLP metrics HTTP path '/v1/metrics' to the endpoint if the
171-
protocol is http/protobuf.
175+
protocol is http/protobuf and it doesn't already exist.
172176
173177
Returns:
174178
string: the endpoint, optionally appended with metrics path
175179
"""
176-
if endpoint and protocol == "http/protobuf":
177-
return "/".join([endpoint.strip("/"), "v1/metrics"])
180+
if endpoint and protocol == "http/protobuf" \
181+
and not endpoint.strip("/").endswith(METRICS_HTTP_PATH):
182+
return "/".join([endpoint.strip("/"), METRICS_HTTP_PATH])
178183
return endpoint
179184

180185

tests/test_options.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,16 @@ def test_get_traces_endpoint_with_http_proto_protocol_returns_correctly_formatte
488488
options = HoneycombOptions(exporter_protocol=protocol)
489489
assert options.get_traces_endpoint() == EXPECTED_ENDPOINT
490490

491+
def test_get_traces_endpoint_with_traces_path_and_http_proto_returns_corretly_formatted_endpoint(monkeypatch):
492+
# http
493+
protocol = EXPORTER_PROTOCOL_HTTP_PROTO
494+
495+
# endpoint already has /v1/traces
496+
endpoint = DEFAULT_API_ENDPOINT + "/v1/traces"
497+
498+
# set endpoint in options
499+
options = HoneycombOptions(exporter_protocol=protocol, endpoint=endpoint)
500+
assert options.get_traces_endpoint() == endpoint
491501

492502
def test_get_metrics_endpoint_with_grpc_protocol_returns_correctly_formatted_endpoint(monkeypatch):
493503
# grpc
@@ -546,6 +556,16 @@ def test_get_metrics_endpoint_with_http_proto_protocol_returns_correctly_formatt
546556
options = HoneycombOptions(exporter_protocol=protocol)
547557
assert options.get_metrics_endpoint() == EXPECTED_ENDPOINT
548558

559+
def test_get_metrics_endpoint_with_metrics_path_and_http_proto_returns_corretly_formatted_endpoint(monkeypatch):
560+
# http
561+
protocol = EXPORTER_PROTOCOL_HTTP_PROTO
562+
563+
# endpoint already has /v1/metrics
564+
endpoint = DEFAULT_API_ENDPOINT + "/v1/metrics"
565+
566+
# set endpoint in options
567+
options = HoneycombOptions(exporter_protocol=protocol, endpoint=endpoint)
568+
assert options.get_metrics_endpoint() == endpoint
549569

550570
def test_debug_sets_log_level_to_debug():
551571
options = HoneycombOptions(debug=True)

0 commit comments

Comments
 (0)