Skip to content

Commit

Permalink
Merge pull request #36166 from siewp/fix-otel-traces-protocol-config
Browse files Browse the repository at this point in the history
Fix tracing protocol configuration to only allow grpc
  • Loading branch information
aloubyansky authored Jan 14, 2024
2 parents 2e1aae2 + 7b5f270 commit efe8a1d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* Currently, only {@code grpc} is allowed.
*/
@WithDefault(Protocol.HTTP_PROTOBUF)
@WithDefault(Protocol.GRPC)
Optional<String> protocol();

public static class Protocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit efe8a1d

Please sign in to comment.