Skip to content

Commit

Permalink
Fix native mode and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Nov 6, 2023
1 parent 7f130a9 commit 57c7e9b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 29 deletions.
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
<opentelemetry.version>1.30.1</opentelemetry.version>
<opentelemetry-alpha.version>1.30.0-alpha</opentelemetry-alpha.version>

<!-- 2.24.0 and 2.25.x fail with graalvm. Otel is behind as well but it seems to work ok-->
<gcp-opentelemetry.version>0.23.0</gcp-opentelemetry.version>
<!-- 2.24.0 and 2.25.0 fail with graalvm -->
<gax-grpc.version>2.23.0</gax-grpc.version>
<gcp-opentelemetry.version>0.25.2</gcp-opentelemetry.version>
<gax-grpc.version>2.37.0</gax-grpc.version>
<google-auto-value-annotations.version>1.8.2</google-auto-value-annotations.version>

<assertj-core.version>3.24.2</assertj-core.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,10 @@ public class LateBoundSpanProcessor implements SpanProcessor {
private boolean warningLogged = false;
private SpanProcessor delegate;

public LateBoundSpanProcessor() {
}

public LateBoundSpanProcessor(SpanProcessor delegate) {
this.delegate = delegate;
}

// fixme remove this method
/**
* Set the actual {@link SpanProcessor} to use as the delegate.
*
* @param delegate Properly constructed {@link SpanProcessor} for processing spans.
*/
public void setSpanProcessorDelegate(SpanProcessor delegate) {
this.delegate = delegate;
}

/**
* If we haven't previously logged an error,
* log an error about a missing {@code delegate} and set {@code warningLogged=true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.opentelemetry.deployment.exporter.otlp.ExternalOtelExporterBuildItem;

@BuildSteps(onlyIf = GcpExporterProcessor.GcpExporterEnabled.class)
Expand All @@ -45,10 +46,20 @@ void registerExternalExporter(BuildProducer<ExternalOtelExporterBuildItem> build
@BuildStep
NativeImageConfigBuildItem nativeImageConfiguration() {
NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder()
.addRuntimeReinitializedClass("com.google.protobuf.UnsafeUtil");
.addRuntimeReinitializedClass("com.google.protobuf.UnsafeUtil")
.addRuntimeInitializedClass("io.grpc.netty.shaded.io.grpc.netty.UdsNameResolverProvider")
.addRuntimeReinitializedClass("io.grpc.netty.shaded.io.grpc.netty.UdsNameResolverProvider");
return builder.build();
}

@BuildStep
public void configureNativeExecutable(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(
ReflectiveClassBuildItem.builder("io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators")
.methods()
.build());
}

@BuildStep
@Record(RUNTIME_INIT)
SyntheticBeanBuildItem installBatchSpanProcessorForGcp(GcpRecorder recorder,
Expand Down
10 changes: 0 additions & 10 deletions quarkus-opentelemetry-exporter-gcp/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@
<artifactId>exporter-trace</artifactId>
<version>${gcp-opentelemetry.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;

import org.threeten.bp.Duration;

Expand All @@ -27,6 +29,7 @@
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.MethodDescriptor;
import io.grpc.NameResolver;
import io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLogLevel;
import io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLogger;
import io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory;
Expand Down Expand Up @@ -171,6 +174,37 @@ static sun.misc.Unsafe getUnsafe() {
}
}

/**
* Copy from io.quarkus.grpc.common.runtime.graal.Target_io_grpc_netty_UdsNameResolverProvider
*/
@TargetClass(className = "io.grpc.netty.shaded.io.grpc.netty.UdsNameResolverProvider", onlyWith = NoDomainSocketPredicate.class)
final class Target_io_grpc_netty_shaded_io_grpc_netty_UdsNameResolverProvider {

@Substitute
protected boolean isAvailable() {
return false;
}

@Substitute
public Object newNameResolver(URI targetUri, NameResolver.Args args) {
// gRPC calls this method without calling isAvailable, so, make sure we do not touch the UdsNameResolver class.
// (as it requires domain sockets)
return null;
}
}

final class NoDomainSocketPredicate implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
try {
this.getClass().getClassLoader().loadClass("io.grpc.netty.shaded.io.netty.channel.unix.DomainSocketAddress");
return false;
} catch (Exception ignored) {
return true;
}
}
}

@TargetClass(className = "io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory")
final class Targetio_grpc_netty_shaded_io_netty_util_internal_logging_InternalLoggerFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.opentelemetry.deployment.exporter.otlp.ExternalOtelExporterBuildItem;

Expand Down

0 comments on commit 57c7e9b

Please sign in to comment.