diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/OpenTelemetryProducer.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/OpenTelemetryProducer.java index f2087cdbb0b86..ba1ca3cd57436 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/OpenTelemetryProducer.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/OpenTelemetryProducer.java @@ -30,6 +30,7 @@ import io.quarkus.arc.DefaultBean; import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig; import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; +import io.quarkus.opentelemetry.runtime.exporter.otlp.RemoveableLateBoundBatchSpanProcessor; import io.quarkus.opentelemetry.runtime.tracing.DelayedAttributes; import io.quarkus.opentelemetry.runtime.tracing.DropTargetsSampler; import io.quarkus.opentelemetry.runtime.tracing.TracerRecorder; @@ -154,7 +155,8 @@ public SdkTracerProviderBuilder apply(SdkTracerProviderBuilder builder, ConfigProperties configProperties) { if (oTelBuildConfig.traces().enabled().orElse(TRUE)) { idGenerator.stream().findFirst().ifPresent(builder::setIdGenerator); // from cdi - spanProcessors.stream().forEach(builder::addSpanProcessor); + spanProcessors.stream().filter(sp -> !(sp instanceof RemoveableLateBoundBatchSpanProcessor)) + .forEach(builder::addSpanProcessor); } return builder; } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/LateBoundBatchSpanProcessor.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/LateBoundBatchSpanProcessor.java index 06d7e07f38b3d..dde43e7c9dcc0 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/LateBoundBatchSpanProcessor.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/LateBoundBatchSpanProcessor.java @@ -14,19 +14,13 @@ * is started, enabling Quarkus to instantiate a {@link io.opentelemetry.api.trace.TracerProvider} * during static initialization and set a {@link BatchSpanProcessor} delegate during runtime initialization. */ -@Deprecated public class LateBoundBatchSpanProcessor implements SpanProcessor { private static final Logger log = Logger.getLogger(LateBoundBatchSpanProcessor.class); private boolean warningLogged = false; private BatchSpanProcessor delegate; - /** - * Set the actual {@link BatchSpanProcessor} to use as the delegate. - * - * @param delegate Properly constructed {@link BatchSpanProcessor} for processing spans. - */ - public void setBatchSpanProcessorDelegate(BatchSpanProcessor delegate) { + public LateBoundBatchSpanProcessor(BatchSpanProcessor delegate) { this.delegate = delegate; } 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 b03a806eaee35..02087407d5534 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 @@ -40,40 +40,36 @@ public Function, LateBou OTelRuntimeConfig otelRuntimeConfig, OtlpExporterRuntimeConfig exporterRuntimeConfig, Supplier vertx) { - var result = new LateBoundBatchSpanProcessor(); URI grpcBaseUri = getGrpcBaseUri(exporterRuntimeConfig); // do the creation and validation here in order to preserve backward compatibility return new Function<>() { @Override public LateBoundBatchSpanProcessor apply( SyntheticCreationalContext context) { - if (otelRuntimeConfig.sdkDisabled()) { - return result; + if (otelRuntimeConfig.sdkDisabled() || grpcBaseUri == null) { + return RemoveableLateBoundBatchSpanProcessor.INSTANCE; } - // Only create the OtlpGrpcSpanExporter if an endpoint was set in runtime config and was properly validated at startup - if (grpcBaseUri != null) { - try { - Instance spanExporters = context.getInjectedReference(new TypeLiteral<>() { - }); - if (spanExporters.isUnsatisfied()) { - var spanExporter = createOtlpGrpcSpanExporter(exporterRuntimeConfig, vertx.get(), grpcBaseUri); - - BatchSpanProcessorBuilder processorBuilder = BatchSpanProcessor.builder(spanExporter); - - processorBuilder.setScheduleDelay(otelRuntimeConfig.bsp().scheduleDelay()); - processorBuilder.setMaxQueueSize(otelRuntimeConfig.bsp().maxQueueSize()); - processorBuilder.setMaxExportBatchSize(otelRuntimeConfig.bsp().maxExportBatchSize()); - processorBuilder.setExporterTimeout(otelRuntimeConfig.bsp().exportTimeout()); - // processorBuilder.setMeterProvider() // TODO add meter provider to span processor. - - result.setBatchSpanProcessorDelegate(processorBuilder.build()); - } - } catch (IllegalArgumentException iae) { - throw new IllegalStateException("Unable to install OTLP Exporter", iae); - } + Instance spanExporters = context.getInjectedReference(new TypeLiteral<>() { + }); + if (!spanExporters.isUnsatisfied()) { + return RemoveableLateBoundBatchSpanProcessor.INSTANCE; } - return result; + try { + var spanExporter = createOtlpGrpcSpanExporter(exporterRuntimeConfig, vertx.get(), grpcBaseUri); + + BatchSpanProcessorBuilder processorBuilder = BatchSpanProcessor.builder(spanExporter); + + processorBuilder.setScheduleDelay(otelRuntimeConfig.bsp().scheduleDelay()); + processorBuilder.setMaxQueueSize(otelRuntimeConfig.bsp().maxQueueSize()); + processorBuilder.setMaxExportBatchSize(otelRuntimeConfig.bsp().maxExportBatchSize()); + processorBuilder.setExporterTimeout(otelRuntimeConfig.bsp().exportTimeout()); + // processorBuilder.setMeterProvider() // TODO add meter provider to span processor. + + return new LateBoundBatchSpanProcessor(processorBuilder.build()); + } catch (IllegalArgumentException iae) { + throw new IllegalStateException("Unable to install OTLP Exporter", iae); + } } private SpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfig exporterRuntimeConfig, diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/RemoveableLateBoundBatchSpanProcessor.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/RemoveableLateBoundBatchSpanProcessor.java new file mode 100644 index 0000000000000..66a3cbff07978 --- /dev/null +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/RemoveableLateBoundBatchSpanProcessor.java @@ -0,0 +1,18 @@ +package io.quarkus.opentelemetry.runtime.exporter.otlp; + +import io.quarkus.opentelemetry.runtime.OpenTelemetryProducer; + +/** + * The only point in having this class is to allow {@link OpenTelemetryProducer} + * to easily ignore the configured {@link LateBoundBatchSpanProcessor}. + *

+ * In the future when {@link OpenTelemetryProducer} is replaced by a synthetic bean, this class will no longer be necessary + */ +public final class RemoveableLateBoundBatchSpanProcessor extends LateBoundBatchSpanProcessor { + + public static final RemoveableLateBoundBatchSpanProcessor INSTANCE = new RemoveableLateBoundBatchSpanProcessor(); + + private RemoveableLateBoundBatchSpanProcessor() { + super(null); + } +}