From d5b3e075f3e1d833b8f1a1b9b0d93a9ace7b7edb Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 5 Jul 2023 13:54:02 +0300 Subject: [PATCH] Properly construct instance of LateBoundBatchSpanProcessor This is now done entirely in a CDI producer method which is then fully initialized when OpenTelemetry autoconfigures itself Fixes: #29987 --- .../exporter/otlp/OtlpExporterProcessor.java | 20 --- .../tracing/TracerIdGeneratorBuildItem.java | 19 --- .../deployment/tracing/TracerProcessor.java | 38 +----- .../tracing/TracerProviderBuildItem.java | 18 --- .../tracing/TracerResourceBuildItem.java | 17 --- .../tracing/TracerSpanExportersBuildItem.java | 19 --- .../TracerSpanProcessorsBuildItem.java | 19 --- .../exporter/otlp/OtlpExporterProvider.java | 103 +++++++++++++++- .../runtime/exporter/otlp/OtlpRecorder.java | 115 ------------------ .../runtime/tracing/TracerRecorder.java | 53 +------- ...est.java => OtlpExporterProviderTest.java} | 14 +-- 11 files changed, 117 insertions(+), 318 deletions(-) delete mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerIdGeneratorBuildItem.java delete mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProviderBuildItem.java delete mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerResourceBuildItem.java delete mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanExportersBuildItem.java delete mode 100644 extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanProcessorsBuildItem.java delete mode 100644 extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java rename extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/{OtlpRecorderTest.java => OtlpExporterProviderTest.java} (86%) 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 519b1e33d8794..4735a607c2c67 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 @@ -5,18 +5,11 @@ import java.util.function.BooleanSupplier; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; -import io.quarkus.arc.deployment.BeanContainerBuildItem; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.BuildSteps; -import io.quarkus.deployment.annotations.ExecutionTime; -import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig; import io.quarkus.opentelemetry.runtime.config.build.exporter.OtlpExporterBuildConfig; -import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; -import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; import io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpExporterProvider; -import io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpRecorder; @BuildSteps(onlyIf = OtlpExporterProcessor.OtlpExporterEnabled.class) public class OtlpExporterProcessor { @@ -39,17 +32,4 @@ AdditionalBeanBuildItem createBatchSpanProcessor() { .addBeanClass(OtlpExporterProvider.class) .setUnremovable().build(); } - - @BuildStep - @Record(ExecutionTime.RUNTIME_INIT) - void installBatchSpanProcessorForOtlp( - OtlpRecorder recorder, - LaunchModeBuildItem launchModeBuildItem, - OTelRuntimeConfig otelRuntimeConfig, - OtlpExporterRuntimeConfig exporterRuntimeConfig, - BeanContainerBuildItem beanContainerBuildItem) { - recorder.installBatchSpanProcessorForOtlp(otelRuntimeConfig, - exporterRuntimeConfig, - launchModeBuildItem.getLaunchMode()); - } } diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerIdGeneratorBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerIdGeneratorBuildItem.java deleted file mode 100644 index 7374cb8476280..0000000000000 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerIdGeneratorBuildItem.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.quarkus.opentelemetry.deployment.tracing; - -import java.util.Optional; - -import io.opentelemetry.sdk.trace.IdGenerator; -import io.quarkus.builder.item.SimpleBuildItem; -import io.quarkus.runtime.RuntimeValue; - -public final class TracerIdGeneratorBuildItem extends SimpleBuildItem { - private final RuntimeValue> idGenerator; - - public TracerIdGeneratorBuildItem(RuntimeValue> idGenerator) { - this.idGenerator = idGenerator; - } - - public RuntimeValue> getIdGenerator() { - return idGenerator; - } -} diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java index c958840b8e702..35641cf858a20 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java @@ -143,42 +143,14 @@ void dropNames( @BuildStep @Record(ExecutionTime.STATIC_INIT) - TracerIdGeneratorBuildItem createIdGenerator(TracerRecorder recorder, - BeanContainerBuildItem beanContainerBuildItem) { - return new TracerIdGeneratorBuildItem(recorder.createIdGenerator()); - } - - @BuildStep - @Record(ExecutionTime.STATIC_INIT) - TracerResourceBuildItem createResource(TracerRecorder recorder, - ApplicationInfoBuildItem appInfo, - BeanContainerBuildItem beanContainerBuildItem) { - String serviceName = appInfo.getName(); - String serviceVersion = appInfo.getVersion(); - return new TracerResourceBuildItem(recorder.createResource(Version.getVersion(), serviceName, serviceVersion)); - } - - @BuildStep - @Record(ExecutionTime.STATIC_INIT) - TracerSpanExportersBuildItem createSpanExporters(TracerRecorder recorder, - BeanContainerBuildItem beanContainerBuildItem) { - return new TracerSpanExportersBuildItem(recorder.createSpanExporter()); - } - - @BuildStep - @Record(ExecutionTime.STATIC_INIT) - TracerSpanProcessorsBuildItem createSpanProcessors(TracerRecorder recorder, - BeanContainerBuildItem beanContainerBuildItem) { - return new TracerSpanProcessorsBuildItem(recorder.createSpanProcessors()); - } - - @BuildStep - @Record(ExecutionTime.STATIC_INIT) - void setupTracer( + void staticInitSetup( TracerRecorder recorder, + ApplicationInfoBuildItem appInfo, + BeanContainerBuildItem beanContainerBuildItem, DropNonApplicationUrisBuildItem dropNonApplicationUris, DropStaticResourcesBuildItem dropStaticResources) { - + recorder.setAttributes(beanContainerBuildItem.getValue(), Version.getVersion(), + appInfo.getName(), appInfo.getVersion()); recorder.setupSampler( dropNonApplicationUris.getDropNames(), dropStaticResources.getDropNames()); diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProviderBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProviderBuildItem.java deleted file mode 100644 index a912f3b776e05..0000000000000 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProviderBuildItem.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.quarkus.opentelemetry.deployment.tracing; - -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.quarkus.builder.item.SimpleBuildItem; -import io.quarkus.runtime.RuntimeValue; - -public final class TracerProviderBuildItem extends SimpleBuildItem { - - private final RuntimeValue tracerProvider; - - TracerProviderBuildItem(RuntimeValue tracerProvider) { - this.tracerProvider = tracerProvider; - } - - public RuntimeValue getTracerProvider() { - return tracerProvider; - } -} diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerResourceBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerResourceBuildItem.java deleted file mode 100644 index 824bbff551e03..0000000000000 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerResourceBuildItem.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.opentelemetry.deployment.tracing; - -import io.opentelemetry.sdk.resources.Resource; -import io.quarkus.builder.item.SimpleBuildItem; -import io.quarkus.runtime.RuntimeValue; - -public final class TracerResourceBuildItem extends SimpleBuildItem { - private final RuntimeValue resource; - - public TracerResourceBuildItem(RuntimeValue resource) { - this.resource = resource; - } - - public RuntimeValue getResource() { - return resource; - } -} diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanExportersBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanExportersBuildItem.java deleted file mode 100644 index 629f911e17269..0000000000000 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanExportersBuildItem.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.quarkus.opentelemetry.deployment.tracing; - -import java.util.List; - -import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.quarkus.builder.item.SimpleBuildItem; -import io.quarkus.runtime.RuntimeValue; - -public final class TracerSpanExportersBuildItem extends SimpleBuildItem { - private final RuntimeValue> spanExporters; - - public TracerSpanExportersBuildItem(RuntimeValue> spanExporters) { - this.spanExporters = spanExporters; - } - - public RuntimeValue> getSpanExporters() { - return spanExporters; - } -} diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanProcessorsBuildItem.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanProcessorsBuildItem.java deleted file mode 100644 index 0b0209f72fef0..0000000000000 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerSpanProcessorsBuildItem.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.quarkus.opentelemetry.deployment.tracing; - -import java.util.List; - -import io.opentelemetry.sdk.trace.SpanProcessor; -import io.quarkus.builder.item.SimpleBuildItem; -import io.quarkus.runtime.RuntimeValue; - -public final class TracerSpanProcessorsBuildItem extends SimpleBuildItem { - private final RuntimeValue> spanProcessors; - - public TracerSpanProcessorsBuildItem(RuntimeValue> spanExporters) { - this.spanProcessors = spanExporters; - } - - public RuntimeValue> getSpanProcessors() { - return spanProcessors; - } -} diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProvider.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProvider.java index 4d8b016d97b02..58bc9a1dd6dec 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProvider.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProvider.java @@ -1,14 +1,113 @@ package io.quarkus.opentelemetry.runtime.exporter.otlp; +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 java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +import jakarta.enterprise.inject.Instance; import jakarta.enterprise.inject.Produces; import jakarta.inject.Singleton; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; +import io.quarkus.opentelemetry.runtime.config.runtime.exporter.CompressionType; +import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; + @Deprecated @Singleton public class OtlpExporterProvider { + @Produces @Singleton - public LateBoundBatchSpanProcessor batchSpanProcessorForOtlp() { - return new LateBoundBatchSpanProcessor(); + public LateBoundBatchSpanProcessor batchSpanProcessorForOtlp(OTelRuntimeConfig otelRuntimeConfig, + OtlpExporterRuntimeConfig exporterRuntimeConfig, + Instance spanExporters) { + var result = new LateBoundBatchSpanProcessor(); + + if (otelRuntimeConfig.sdkDisabled()) { + return result; + } + + String endpoint = resolveEndpoint(exporterRuntimeConfig).trim(); + + // Only create the OtlpGrpcSpanExporter if an endpoint was set in runtime config + if (endpoint.length() > 0) { + try { + // CDI exporter was already added to a processor by OTEL + if (spanExporters.isUnsatisfied()) { + var spanExporter = createOtlpGrpcSpanExporter(exporterRuntimeConfig, endpoint); + + 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); + } + } + + return result; + } + + static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) { + String endpoint = runtimeConfig.traces().legacyEndpoint() + .filter(OtlpExporterProvider::excludeDefaultEndpoint) + .orElse(runtimeConfig.traces().endpoint() + .filter(OtlpExporterProvider::excludeDefaultEndpoint) + .orElse(runtimeConfig.endpoint() + .filter(OtlpExporterProvider::excludeDefaultEndpoint) + .orElse(DEFAULT_GRPC_BASE_URI))); + return endpoint.trim(); + } + + private static boolean excludeDefaultEndpoint(String endpoint) { + return !DEFAULT_GRPC_BASE_URI.equals(endpoint); + } + + private OtlpGrpcSpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfig exporterRuntimeConfig, String endpoint) { + OtlpGrpcSpanExporterBuilder exporterBuilder = OtlpGrpcSpanExporter.builder() + .setEndpoint(endpoint) + .setTimeout(exporterRuntimeConfig.traces().timeout()); + + // FIXME TLS Support. Was not available before but will be available soon. + // exporterRuntimeConfig.traces.certificate.ifPresent(exporterBuilder::setTrustedCertificates); + // exporterRuntimeConfig.client.ifPresent(exporterBuilder::setClientTls); + exporterRuntimeConfig.traces().headers().ifPresent(new Consumer>() { + @Override + public void accept(final List headers) { + for (Map.Entry entry : convertKeyValueListToMap(headers).entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + exporterBuilder.addHeader(key, value); + } + } + }); + exporterRuntimeConfig.traces().compression() + .ifPresent(new Consumer() { + @Override + public void accept(CompressionType compression) { + exporterBuilder.setCompression(compression.getValue()); + } + }); + + if (!exporterRuntimeConfig.traces().protocol().orElse("").equals(HTTP_PROTOBUF)) { + throw new IllegalStateException("Only the GRPC Exporter is currently supported. " + + "Please check `otel.exporter.otlp.traces.protocol` property"); + } + return exporterBuilder.build(); } } 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 deleted file mode 100644 index 414032b18ea3d..0000000000000 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java +++ /dev/null @@ -1,115 +0,0 @@ -package io.quarkus.opentelemetry.runtime.exporter.otlp; - -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 java.util.List; -import java.util.Map; -import java.util.function.Consumer; - -import jakarta.enterprise.inject.Any; -import jakarta.enterprise.inject.spi.CDI; - -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder; -import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; -import io.quarkus.opentelemetry.runtime.config.runtime.exporter.CompressionType; -import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; -import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.annotations.Recorder; - -@Recorder -public class OtlpRecorder { - - static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) { - String endpoint = runtimeConfig.traces().legacyEndpoint() - .filter(OtlpRecorder::excludeDefaultEndpoint) - .orElse(runtimeConfig.traces().endpoint() - .filter(OtlpRecorder::excludeDefaultEndpoint) - .orElse(runtimeConfig.endpoint() - .filter(OtlpRecorder::excludeDefaultEndpoint) - .orElse(DEFAULT_GRPC_BASE_URI))); - return endpoint.trim(); - } - - private static boolean excludeDefaultEndpoint(String endpoint) { - return !DEFAULT_GRPC_BASE_URI.equals(endpoint); - } - - public void installBatchSpanProcessorForOtlp( - OTelRuntimeConfig otelRuntimeConfig, - OtlpExporterRuntimeConfig exporterRuntimeConfig, - LaunchMode launchMode) { - - if (otelRuntimeConfig.sdkDisabled()) { - return; - } - String endpoint = resolveEndpoint(exporterRuntimeConfig).trim(); - - // Only create the OtlpGrpcSpanExporter if an endpoint was set in runtime config - if (endpoint.length() > 0) { - try { - // Load span exporter if provided by user - SpanExporter spanExporter = CDI.current() - .select(SpanExporter.class, Any.Literal.INSTANCE).stream().findFirst().orElse(null); - // CDI exporter was already added to a processor by OTEL - if (spanExporter == null) { - spanExporter = createOtlpGrpcSpanExporter(exporterRuntimeConfig, endpoint); - - // Create BatchSpanProcessor for OTLP and install into LateBoundBatchSpanProcessor - LateBoundBatchSpanProcessor delayedProcessor = CDI.current() - .select(LateBoundBatchSpanProcessor.class, Any.Literal.INSTANCE).get(); - - 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. - - delayedProcessor.setBatchSpanProcessorDelegate(processorBuilder.build()); - } - } catch (IllegalArgumentException iae) { - throw new IllegalStateException("Unable to install OTLP Exporter", iae); - } - } - } - - private OtlpGrpcSpanExporter createOtlpGrpcSpanExporter(OtlpExporterRuntimeConfig exporterRuntimeConfig, String endpoint) { - OtlpGrpcSpanExporterBuilder exporterBuilder = OtlpGrpcSpanExporter.builder() - .setEndpoint(endpoint) - .setTimeout(exporterRuntimeConfig.traces().timeout()); - - // FIXME TLS Support. Was not available before but will be available soon. - // exporterRuntimeConfig.traces.certificate.ifPresent(exporterBuilder::setTrustedCertificates); - // exporterRuntimeConfig.client.ifPresent(exporterBuilder::setClientTls); - exporterRuntimeConfig.traces().headers().ifPresent(new Consumer>() { - @Override - public void accept(final List headers) { - for (Map.Entry entry : convertKeyValueListToMap(headers).entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - exporterBuilder.addHeader(key, value); - } - } - }); - exporterRuntimeConfig.traces().compression() - .ifPresent(new Consumer() { - @Override - public void accept(CompressionType compression) { - exporterBuilder.setCompression(compression.getValue()); - } - }); - - if (!exporterRuntimeConfig.traces().protocol().orElse("").equals(HTTP_PROTOBUF)) { - throw new IllegalStateException("Only the GRPC Exporter is currently supported. " + - "Please check `otel.exporter.otlp.traces.protocol` property"); - } - return exporterBuilder.build(); - } -} diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/TracerRecorder.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/TracerRecorder.java index 7075f8389532e..163ab17705b61 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/TracerRecorder.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/TracerRecorder.java @@ -2,22 +2,12 @@ import java.util.HashSet; import java.util.List; -import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; - -import jakarta.enterprise.inject.Any; -import jakarta.enterprise.inject.Instance; -import jakarta.enterprise.inject.spi.BeanManager; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.trace.IdGenerator; -import io.opentelemetry.sdk.trace.SpanProcessor; -import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; -import io.quarkus.arc.Arc; -import io.quarkus.runtime.RuntimeValue; +import io.quarkus.arc.runtime.BeanContainer; import io.quarkus.runtime.annotations.Recorder; @Recorder @@ -27,24 +17,13 @@ public class TracerRecorder { public static final Set dropStaticResourceTargets = new HashSet<>(); /* STATIC INIT */ - public RuntimeValue> createIdGenerator() { - BeanManager beanManager = Arc.container().beanManager(); - - Instance idGenerator = beanManager.createInstance() - .select(IdGenerator.class, Any.Literal.INSTANCE); - - return new RuntimeValue<>(idGenerator.isResolvable() ? Optional.of(idGenerator.get()) : Optional.empty()); - } - - /* STATIC INIT */ - public RuntimeValue createResource( + public void setAttributes( + BeanContainer beanContainer, String quarkusVersion, String serviceName, String serviceVersion) { - BeanManager beanManager = Arc.container().beanManager(); - DelayedAttributes delayedAttributes = beanManager.createInstance() - .select(DelayedAttributes.class, Any.Literal.INSTANCE).get(); + DelayedAttributes delayedAttributes = beanContainer.beanInstance(DelayedAttributes.class); delayedAttributes.setAttributesDelegate(Resource.getDefault() .merge(Resource.create( @@ -54,30 +33,6 @@ public RuntimeValue createResource( ResourceAttributes.WEBENGINE_NAME, "Quarkus", ResourceAttributes.WEBENGINE_VERSION, quarkusVersion))) .getAttributes()); - - return new RuntimeValue<>(Resource.create(delayedAttributes)); - } - - /* STATIC INIT */ - public RuntimeValue> createSpanExporter() { - BeanManager beanManager = Arc.container().beanManager(); - // Find all SpanExporter instances - Instance allExporters = beanManager.createInstance() - .select(SpanExporter.class, Any.Literal.INSTANCE); - - return new RuntimeValue<>(allExporters.stream().collect(Collectors.toList())); - } - - /* STATIC INIT */ - public RuntimeValue> createSpanProcessors() { - BeanManager beanManager = Arc.container().beanManager(); - - // Find all SpanProcessor instances - Instance allProcessors = beanManager.createInstance() - .select(SpanProcessor.class, Any.Literal.INSTANCE); - - return new RuntimeValue<>(allProcessors.stream().collect(Collectors.toList())); - } /* STATIC INIT */ diff --git a/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java b/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java similarity index 86% rename from extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java rename to extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java index 8fdb47c4c8e96..9b535bcae226f 100644 --- a/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java +++ b/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpExporterProviderTest.java @@ -13,12 +13,12 @@ import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig; -class OtlpRecorderTest { +class OtlpExporterProviderTest { @Test public void resolveEndpoint_legacyWins() { assertEquals("http://localhost:1111/", - OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + OtlpExporterProvider.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( + OtlpExporterProvider.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( + OtlpExporterProvider.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( + OtlpExporterProvider.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( + OtlpExporterProvider.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( + OtlpExporterProvider.resolveEndpoint(createOtlpExporterRuntimeConfig( null, null, null)));