From 2632e1cbb9013c6a5b1712308bf8ccc0b23c40af Mon Sep 17 00:00:00 2001 From: brunobat Date: Mon, 16 Oct 2023 11:56:23 +0100 Subject: [PATCH] support external exporters in CDI --- .../deployment/OpenTelemetryBuildItem.java | 18 ------------------ .../otlp/ExternalOtelExporterBuildItem.java | 18 ++++++++++++++++++ .../exporter/otlp/OtlpExporterProcessor.java | 18 ++++++++++++------ ...Recorder.java => OTelExporterRecorder.java} | 10 +++++----- ...ExporterUtil.java => OTelExporterUtil.java} | 4 ++-- .../exporter/otlp/VertxGrpcExporter.java | 2 +- .../exporter/otlp/VertxHttpExporter.java | 2 +- .../otlp/OtlpExporterProviderTest.java | 12 ++++++------ 8 files changed, 45 insertions(+), 39 deletions(-) delete mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/OpenTelemetryBuildItem.java create mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/ExternalOtelExporterBuildItem.java rename extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/{OtlpRecorder.java => OTelExporterRecorder.java} (97%) rename extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/{OtlpExporterUtil.java => OTelExporterUtil.java} (88%) diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/OpenTelemetryBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/OpenTelemetryBuildItem.java deleted file mode 100644 index 743782aa88c14..0000000000000 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/OpenTelemetryBuildItem.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.quarkus.opentelemetry.deployment; - -import io.opentelemetry.api.OpenTelemetry; -import io.quarkus.builder.item.SimpleBuildItem; -import io.quarkus.runtime.RuntimeValue; - -public final class OpenTelemetryBuildItem extends SimpleBuildItem { - - private final RuntimeValue value; - - public OpenTelemetryBuildItem(RuntimeValue value) { - this.value = value; - } - - public RuntimeValue getValue() { - return value; - } -} diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/ExternalOtelExporterBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/ExternalOtelExporterBuildItem.java new file mode 100644 index 0000000000000..685cbf3f04400 --- /dev/null +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/ExternalOtelExporterBuildItem.java @@ -0,0 +1,18 @@ +package io.quarkus.opentelemetry.deployment.exporter.otlp; + +import io.quarkus.builder.item.MultiBuildItem; + +/** + * Build item to be used by Quarkiverse exporters to register themselves as an external exporter. + */ +final public class ExternalOtelExporterBuildItem extends MultiBuildItem { + final private String exporterName; + + public ExternalOtelExporterBuildItem(String exporterName) { + this.exporterName = exporterName; + } + + public String getExporterName() { + return exporterName; + } +} diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java index 1c03b5bd44920..8d2d594d3ca44 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java @@ -2,6 +2,7 @@ import static io.quarkus.opentelemetry.runtime.config.build.ExporterType.Constants.CDI_VALUE; +import java.util.List; import java.util.function.BooleanSupplier; import jakarta.enterprise.inject.Instance; @@ -27,7 +28,7 @@ import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; import io.quarkus.opentelemetry.runtime.exporter.otlp.EndUserSpanProcessor; import io.quarkus.opentelemetry.runtime.exporter.otlp.LateBoundBatchSpanProcessor; -import io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpRecorder; +import io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterRecorder; import io.quarkus.runtime.TlsConfig; import io.quarkus.vertx.core.deployment.CoreVertxBuildItem; @@ -60,12 +61,18 @@ void createEndUserSpanProcessor( @SuppressWarnings("deprecation") @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - SyntheticBeanBuildItem createBatchSpanProcessor(OtlpRecorder recorder, + void createBatchSpanProcessor(OTelExporterRecorder recorder, OTelRuntimeConfig otelRuntimeConfig, OtlpExporterRuntimeConfig exporterRuntimeConfig, TlsConfig tlsConfig, - CoreVertxBuildItem vertxBuildItem) { - return SyntheticBeanBuildItem + CoreVertxBuildItem vertxBuildItem, + List externalOtelExporterBuildItem, + BuildProducer syntheticBeanBuildItemBuildProducer) { + if (!externalOtelExporterBuildItem.isEmpty()) { + // if there is an external exporter, we don't want to create the default one + return; + } + syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem .configure(LateBoundBatchSpanProcessor.class) .types(SpanProcessor.class) .setRuntimeInit() @@ -75,7 +82,6 @@ SyntheticBeanBuildItem createBatchSpanProcessor(OtlpRecorder recorder, new Type[] { ClassType.create(DotName.createSimple(SpanExporter.class.getName())) }, null)) .createWith(recorder.batchSpanProcessorForOtlp(otelRuntimeConfig, exporterRuntimeConfig, tlsConfig, vertxBuildItem.getVertx())) - .done(); - + .done()); } } 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/OTelExporterRecorder.java similarity index 97% rename from extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java rename to extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OTelExporterRecorder.java index 2da845ca59599..8757df5a2dcdd 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/OTelExporterRecorder.java @@ -38,7 +38,7 @@ @SuppressWarnings("deprecation") @Recorder -public class OtlpRecorder { +public class OTelExporterRecorder { public Function, LateBoundBatchSpanProcessor> batchSpanProcessorForOtlp( OTelRuntimeConfig otelRuntimeConfig, @@ -174,11 +174,11 @@ private URI getBaseUri(OtlpExporterRuntimeConfig exporterRuntimeConfig) { static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) { String endpoint = runtimeConfig.traces().legacyEndpoint() - .filter(OtlpRecorder::excludeDefaultEndpoint) + .filter(OTelExporterRecorder::excludeDefaultEndpoint) .orElse(runtimeConfig.traces().endpoint() - .filter(OtlpRecorder::excludeDefaultEndpoint) + .filter(OTelExporterRecorder::excludeDefaultEndpoint) .orElse(runtimeConfig.endpoint() - .filter(OtlpRecorder::excludeDefaultEndpoint) + .filter(OTelExporterRecorder::excludeDefaultEndpoint) .orElse(DEFAULT_GRPC_BASE_URI))); return endpoint.trim(); } @@ -208,7 +208,7 @@ private void configureTLS(HttpClientOptions options) { options.setKeyCertOptions(toPemKeyCertOptions()); options.setPemTrustOptions(toPemTrustOptions()); - if (OtlpExporterUtil.isHttps(baseUri)) { + if (OTelExporterUtil.isHttps(baseUri)) { options.setSsl(true); options.setUseAlpn(true); } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterUtil.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OTelExporterUtil.java similarity index 88% rename from extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterUtil.java rename to extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OTelExporterUtil.java index 1108a7aca4f24..02aefe66744f9 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterUtil.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OTelExporterUtil.java @@ -3,9 +3,9 @@ import java.net.URI; import java.util.Locale; -final class OtlpExporterUtil { +final class OTelExporterUtil { - private OtlpExporterUtil() { + private OTelExporterUtil() { } static int getPort(URI uri) { diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java index d80e966e8d8a3..22a97a73e35d2 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java @@ -67,7 +67,7 @@ final class VertxGrpcExporter implements SpanExporter { Vertx vertx) { this.type = type; this.exporterMetrics = ExporterMetrics.createGrpcOkHttp(exporterName, type, meterProviderSupplier); - this.server = SocketAddress.inetSocketAddress(OtlpExporterUtil.getPort(grpcBaseUri), grpcBaseUri.getHost()); + this.server = SocketAddress.inetSocketAddress(OTelExporterUtil.getPort(grpcBaseUri), grpcBaseUri.getHost()); this.compressionEnabled = compressionEnabled; this.headers = headersMap; var httpClientOptions = new HttpClientOptions() 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 0ed0ef9764984..ed09c04c0541a 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 @@ -1,6 +1,6 @@ package io.quarkus.opentelemetry.runtime.exporter.otlp; -import static io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpExporterUtil.getPort; +import static io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterUtil.getPort; import java.io.IOException; import java.io.OutputStream; diff --git a/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java b/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java index 50b17e200707e..f7cc1d9451645 100644 --- a/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java +++ b/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java @@ -18,7 +18,7 @@ class OtlpExporterProviderTest { @Test public void resolveEndpoint_legacyWins() { assertEquals("http://localhost:1111/", - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( DEFAULT_GRPC_BASE_URI, "http://localhost:1111/", "http://localhost:2222/"))); @@ -27,7 +27,7 @@ public void resolveEndpoint_legacyWins() { @Test public void resolveEndpoint_newWins() { assertEquals("http://localhost:2222/", - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( "http://localhost:1111/", DEFAULT_GRPC_BASE_URI, "http://localhost:2222/"))); @@ -36,7 +36,7 @@ public void resolveEndpoint_newWins() { @Test public void resolveEndpoint_globalWins() { assertEquals("http://localhost:1111/", - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( "http://localhost:1111/", DEFAULT_GRPC_BASE_URI, DEFAULT_GRPC_BASE_URI))); @@ -45,7 +45,7 @@ public void resolveEndpoint_globalWins() { @Test public void resolveEndpoint_legacyTraceWins() { assertEquals("http://localhost:2222/", - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( DEFAULT_GRPC_BASE_URI, null, "http://localhost:2222/"))); @@ -54,7 +54,7 @@ public void resolveEndpoint_legacyTraceWins() { @Test public void resolveEndpoint_legacyGlobalWins() { assertEquals(DEFAULT_GRPC_BASE_URI, - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( DEFAULT_GRPC_BASE_URI, null, null))); @@ -63,7 +63,7 @@ public void resolveEndpoint_legacyGlobalWins() { @Test public void resolveEndpoint_testIsSet() { assertEquals(DEFAULT_GRPC_BASE_URI, - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( null, null, null)));