Skip to content

Commit

Permalink
Fix native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 25, 2024
1 parent 3e52218 commit 117592f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<UnremovableBeanBuildItem> 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<ServiceProviderBuildItem> servicesProducer) {
servicesProducer.produce(
new ServiceProviderBuildItem(ConfigurableLogRecordExporterProvider.class.getName(),
LogsExporterCDIProvider.class.getName()));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? super LogRecordExporter, ConfigProperties, ? extends LogRecordExporter> logRecordExporterCustomizer,
BiFunction<? super LogRecordProcessor, ConfigProperties, ? extends LogRecordProcessor> logRecordProcessorCustomizer,
List<Closeable> 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
Expand Down

0 comments on commit 117592f

Please sign in to comment.