From 35119999a8ac9fea082336e7c86a23a0f3843d78 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 23 Aug 2023 17:29:44 +0300 Subject: [PATCH] Take OTel exporter endpoint path into account Fixes: #35501 --- .../exporter/otlp/VertxHttpExporter.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java index 176ca444d8b93..0ed0ef9764984 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java @@ -56,6 +56,7 @@ public CompletableResultCode shutdown() { static final class VertxHttpSender implements HttpSender { private static final String TRACES_PATH = "/v1/traces"; + private final String basePath; private final boolean compressionEnabled; private final Map headers; private final String contentType; @@ -69,6 +70,7 @@ static final class VertxHttpSender implements HttpSender { String contentType, Consumer clientOptionsCustomizer, Vertx vertx) { + this.basePath = determineBasePath(baseUri); this.compressionEnabled = compressionEnabled; this.headers = headersMap; this.contentType = contentType; @@ -81,13 +83,27 @@ static final class VertxHttpSender implements HttpSender { this.client = vertx.createHttpClient(httpClientOptions); } + private static String determineBasePath(URI baseUri) { + String path = baseUri.getPath(); + if (path.isEmpty() || path.equals("/")) { + return ""; + } + if (path.endsWith("/")) { // strip ending slash + path = path.substring(0, path.length() - 1); + } + if (!path.startsWith("/")) { // prepend leading slash + path = "/" + path; + } + return path; + } + @Override public void send(Consumer marshaler, int contentLength, Consumer onResponse, Consumer onError) { - client.request(HttpMethod.POST, TRACES_PATH) + client.request(HttpMethod.POST, basePath + TRACES_PATH) .onSuccess(new Handler<>() { @Override public void handle(HttpClientRequest request) {