From 117592fe5b137eb7c4c4a51dc50c343f22c2ea3c Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 25 Sep 2024 15:14:01 +0300 Subject: [PATCH] Fix native mode --- .../logging/LogHandlerProcessor.java | 67 ++++--------------- .../runtime/graal/Substitutions.java | 26 ------- 2 files changed, 13 insertions(+), 80 deletions(-) diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/logging/LogHandlerProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/logging/LogHandlerProcessor.java index f76e8e0d3a6e6..2c1f3fbe5a4aa 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/logging/LogHandlerProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/logging/LogHandlerProcessor.java @@ -1,87 +1,46 @@ package io.quarkus.opentelemetry.deployment.logging; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; import java.util.function.BooleanSupplier; import java.util.function.Function; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.DotName; -import org.jboss.jandex.FieldInfo; -import org.jboss.jandex.IndexView; -import org.jboss.jandex.MethodInfo; +import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import io.quarkus.agroal.spi.OpenTelemetryInitBuildItem; import io.quarkus.arc.deployment.BeanContainerBuildItem; import io.quarkus.arc.deployment.UnremovableBeanBuildItem; -import io.quarkus.arc.processor.DotNames; +import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.BuildSteps; import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.LogHandlerBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig; import io.quarkus.opentelemetry.runtime.logs.OpenTelemetryLogConfig; import io.quarkus.opentelemetry.runtime.logs.OpenTelemetryLogRecorder; +import io.quarkus.opentelemetry.runtime.logs.spi.LogsExporterCDIProvider; @BuildSteps(onlyIf = LogHandlerProcessor.LogsEnabled.class) class LogHandlerProcessor { private static final DotName LOG_RECORD_EXPORTER = DotName.createSimple(LogRecordExporter.class.getName()); private static final DotName LOG_RECORD_PROCESSOR = DotName.createSimple(LogRecordProcessor.class.getName()); - // private static final DotName LOG_RECORD_HANDLER = DotName.createSimple(Handler.class.getName()); @BuildStep - UnremovableBeanBuildItem ensureProducersAreRetained( - CombinedIndexBuildItem indexBuildItem) { - - IndexView index = indexBuildItem.getIndex(); - - // Find all known SpanExporters and SpanProcessors - Collection knownClasses = new HashSet<>(); - knownClasses.add(LOG_RECORD_EXPORTER.toString()); - index.getAllKnownImplementors(LOG_RECORD_EXPORTER) - .forEach(classInfo -> knownClasses.add(classInfo.name().toString())); - - knownClasses.add(LOG_RECORD_PROCESSOR.toString()); - index.getAllKnownImplementors(LOG_RECORD_PROCESSOR) - .forEach(classInfo -> knownClasses.add(classInfo.name().toString())); - - // knownClasses.add(LOG_RECORD_HANDLER.toString()); - // index.getAllKnownImplementors(LOG_RECORD_HANDLER) - // .forEach(classInfo -> knownClasses.add(classInfo.name().toString())); - - Set retainProducers = new HashSet<>(); - - for (AnnotationInstance annotation : index.getAnnotations(DotNames.PRODUCES)) { - AnnotationTarget target = annotation.target(); - switch (target.kind()) { - case METHOD: - MethodInfo method = target.asMethod(); - String returnType = method.returnType().name().toString(); - if (knownClasses.contains(returnType)) { - retainProducers.add(method.declaringClass().name().toString()); - } - break; - case FIELD: - FieldInfo field = target.asField(); - String fieldType = field.type().name().toString(); - if (knownClasses.contains(fieldType)) { - retainProducers.add(field.declaringClass().name().toString()); - } - break; - default: - break; - } - } + void beanSupport(BuildProducer unremovableProducer) { + unremovableProducer.produce(UnremovableBeanBuildItem.beanTypes(LOG_RECORD_EXPORTER)); + unremovableProducer.produce(UnremovableBeanBuildItem.beanTypes(LOG_RECORD_PROCESSOR)); + } - return new UnremovableBeanBuildItem(new UnremovableBeanBuildItem.BeanClassNamesExclusion(retainProducers)); + @BuildStep + void nativeSupport(BuildProducer servicesProducer) { + servicesProducer.produce( + new ServiceProviderBuildItem(ConfigurableLogRecordExporterProvider.class.getName(), + LogsExporterCDIProvider.class.getName())); } @BuildStep diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/graal/Substitutions.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/graal/Substitutions.java index ea5dcf5d13b34..d63315949936a 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/graal/Substitutions.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/graal/Substitutions.java @@ -1,38 +1,12 @@ package io.quarkus.opentelemetry.runtime.graal; -import java.io.Closeable; -import java.util.List; -import java.util.function.BiFunction; - import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import io.opentelemetry.api.incubator.events.EventLoggerProvider; -import io.opentelemetry.api.metrics.MeterProvider; -import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.logs.LogRecordProcessor; -import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; -import io.opentelemetry.sdk.logs.export.LogRecordExporter; public class Substitutions { - @TargetClass(className = "io.opentelemetry.sdk.autoconfigure.LoggerProviderConfiguration") - static final class Target_LoggerProviderConfiguration { - - @Substitute - static void configureLoggerProvider( - SdkLoggerProviderBuilder loggerProviderBuilder, - ConfigProperties config, - SpiHelper spiHelper, - MeterProvider meterProvider, - BiFunction logRecordExporterCustomizer, - BiFunction logRecordProcessorCustomizer, - List closeables) { - // Logs not supported yet. No need to call LogRecordExporterConfiguration.configureExporter - } - } - @TargetClass(className = "io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider") static final class Target_GlobalEventEmitterProvider { @Substitute