From 7b5f270a18cc6c629707d5884a4a8420cd768a68 Mon Sep 17 00:00:00 2001 From: Pascal Siewert Date: Mon, 25 Sep 2023 19:45:14 +0200 Subject: [PATCH] Fix throwing exception when tracing protocol is not grpc Adjust exception message for unsupported tracing exporter protocols Add test for unsupported otlp exporter protocol config --- .../exporter/otlp/OtlpExporterConfigTest.java | 2 +- .../OtlpExporterUnsupportedProtocolTest.java | 47 +++++++++++++++++++ .../exporter/OtlpExporterTracesConfig.java | 4 +- .../runtime/exporter/otlp/OtlpRecorder.java | 7 +-- 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterUnsupportedProtocolTest.java diff --git a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterConfigTest.java b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterConfigTest.java index 498be3ade7c9d..755934d1739a6 100644 --- a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterConfigTest.java +++ b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterConfigTest.java @@ -16,7 +16,7 @@ public class OtlpExporterConfigTest { static final QuarkusUnitTest TEST = new QuarkusUnitTest() .withEmptyApplication() .overrideConfigKey("otel.traces.exporter", "cdi") - .overrideConfigKey("otel.exporter.otlp.traces.protocol", "http/protobuf") + .overrideConfigKey("otel.exporter.otlp.traces.protocol", "grpc") .overrideConfigKey("quarkus.opentelemetry.tracer.exporter.otlp.endpoint", "http://localhost ") .overrideConfigKey("quarkus.otel.bsp.schedule.delay", "50") .overrideConfigKey("quarkus.otel.bsp.export.timeout", "1s"); diff --git a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterUnsupportedProtocolTest.java b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterUnsupportedProtocolTest.java new file mode 100644 index 0000000000000..e852e8f879e4c --- /dev/null +++ b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterUnsupportedProtocolTest.java @@ -0,0 +1,47 @@ +package io.quarkus.opentelemetry.deployment.exporter.otlp; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class OtlpExporterUnsupportedProtocolTest { + + @RegisterExtension + static final QuarkusUnitTest TEST = new QuarkusUnitTest() + .withEmptyApplication() + .overrideConfigKey("otel.traces.exporter", "cdi") + .overrideConfigKey("quarkus.otel.exporter.otlp.traces.protocol", "http/protobuf") + .overrideConfigKey("quarkus.opentelemetry.tracer.exporter.otlp.endpoint", "http://localhost ") + .overrideConfigKey("quarkus.otel.bsp.schedule.delay", "50") + .overrideConfigKey("quarkus.otel.bsp.export.timeout", "1s") + .assertException(t -> { + Throwable e = t; + IllegalStateException ie = null; + while (e != null) { + if (t instanceof IllegalStateException) { + ie = (IllegalStateException) t; + break; + } + e = e.getCause(); + } + + if (ie == null) { + fail("No IllegalStateException thrown: " + t); + } + assertTrue(ie.getMessage().contains("Only the `grpc` protocol is currently supported."), + ie.getMessage()); + assertTrue(ie.getMessage().contains("`http/protobuf` is available after Quarkus 3.3."), + ie.getMessage()); + assertTrue(ie.getMessage().contains("Please check `otel.exporter.otlp.traces.protocol` property"), + ie.getMessage()); + }); + + @Test + void testNotSupportedProtocolConfig() { + fail(); + } +} diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/runtime/exporter/OtlpExporterTracesConfig.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/runtime/exporter/OtlpExporterTracesConfig.java index 5cc4daa9c2bf5..fcea1f24572ef 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/runtime/exporter/OtlpExporterTracesConfig.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/runtime/exporter/OtlpExporterTracesConfig.java @@ -69,8 +69,10 @@ public interface OtlpExporterTracesConfig { /** * OTLP defines the encoding of telemetry data and the protocol used to exchange data between the client and the * server. Depending on the exporter, the available protocols will be different. + *

+ * Currently, only {@code grpc} is allowed. */ - @WithDefault(Protocol.HTTP_PROTOBUF) + @WithDefault(Protocol.GRPC) Optional protocol(); public static class Protocol { diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java index 414032b18ea3d..31d0de21a916f 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java @@ -2,7 +2,7 @@ import static io.quarkus.opentelemetry.runtime.OpenTelemetryUtil.convertKeyValueListToMap; import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig.DEFAULT_GRPC_BASE_URI; -import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig.Protocol.HTTP_PROTOBUF; +import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig.Protocol.GRPC; import java.util.List; import java.util.Map; @@ -106,8 +106,9 @@ public void accept(CompressionType compression) { } }); - if (!exporterRuntimeConfig.traces().protocol().orElse("").equals(HTTP_PROTOBUF)) { - throw new IllegalStateException("Only the GRPC Exporter is currently supported. " + + if (!exporterRuntimeConfig.traces().protocol().orElse("").equals(GRPC)) { + throw new IllegalStateException("Only the `grpc` protocol is currently supported. " + + "`http/protobuf` is available after Quarkus 3.3. " + "Please check `otel.exporter.otlp.traces.protocol` property"); } return exporterBuilder.build();