Skip to content

Commit

Permalink
Further improve the construction of LateBoundBatchSpanProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jul 18, 2023
1 parent 690c46b commit c50213f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,36 @@ public Function<SyntheticCreationalContext<LateBoundBatchSpanProcessor>, LateBou
OTelRuntimeConfig otelRuntimeConfig,
OtlpExporterRuntimeConfig exporterRuntimeConfig,
Supplier<Vertx> 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<LateBoundBatchSpanProcessor> 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<SpanExporter> 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<SpanExporter> 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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}.
* <p>
* 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);
}
}

0 comments on commit c50213f

Please sign in to comment.