Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instantiation of the exporters for Quarkus v3.2+ #104

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ buildNumber.properties
/.idea/.gitignore
/.idea/
/docs/modules/ROOT/pages/includes/
/docs/quarkus-opentelemetry-exporter-docs.iml
/quarkus-opentelemetry-exporter-common/quarkus-opentelemetry-exporter-common.iml
/quarkus-opentelemetry-exporter-gcp/deployment/quarkus-opentelemetry-exporter-gcp-deployment.iml
/quarkus-opentelemetry-exporter-gcp/integration-tests/quarkus-opentelemetry-exporter-gcp-integration-tests.iml
/quarkus-opentelemetry-exporter-gcp/runtime/quarkus-opentelemetry-exporter-gcp.iml
/migrate.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Exporters are OpenTelemetry SDK Plugins which implement the Exporter interface, and emit telemetry to consumers, usually observability vendors.
Currently, we support this implementation:
* Jaeger
* Google Cloud Platform
* Google Cloud Platform (Not available in native mode)

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:project-version: 1.1.1.Final
:project-version: 2.0.0.Final

:examples-dir: ./../examples/
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Exporters are OpenTelemetry SDK Plugins which implement the Exporter interface,

This exporter sends data to Google Cloud Platform using https://github.com/GoogleCloudPlatform/opentelemetry-operations-java[opentelemetry-operations-java library].

[WARNING]
====
This extension doesn't work on native mode.

The `UdsNameResolverProvider` is forced to be initialized at run time with no good reason.
This can be related to https://github.com/oracle/graal/pull/8230.
====


== Installation

=== Add exporter dependency
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.quarkiverse</groupId>
<artifactId>quarkiverse-parent</artifactId>
<version>12</version>
<version>15</version>
<relativePath /> <!-- always from repository -->
</parent>

Expand Down Expand Up @@ -34,12 +34,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<quarkus.version>3.0.0.CR2</quarkus.version>
<opentelemetry.version>1.23.1</opentelemetry.version>
<opentelemetry-alpha.version>1.23.0-alpha</opentelemetry-alpha.version>
<quarkus.version>3.5.0</quarkus.version>
<opentelemetry.version>1.31.0</opentelemetry.version>
<opentelemetry-alpha.version>1.31.0-alpha</opentelemetry-alpha.version>

<gcp-opentelemetry.version>0.23.0</gcp-opentelemetry.version>
<gax-grpc.version>2.13.0</gax-grpc.version>
<gcp-opentelemetry.version>0.26.0</gcp-opentelemetry.version>
<gax-grpc.version>2.39.0</gax-grpc.version>

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkiverse.opentelemetry.exporter.common.runtime;

/**
* The only point in having this class is to allow {@link TracerProviderCustomizer}
* to easily ignore the configured {@link LateBoundSpanProcessor}.
*/
public final class RemovableLateBoundSpanProcessor extends LateBoundSpanProcessor {

public static final RemovableLateBoundSpanProcessor INSTANCE = new RemovableLateBoundSpanProcessor();

private RemovableLateBoundSpanProcessor() {
super(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@

import java.util.function.BooleanSupplier;

import jakarta.enterprise.inject.Instance;
import jakarta.inject.Singleton;

import org.jboss.jandex.ClassType;
import org.jboss.jandex.DotName;
import org.jboss.jandex.ParameterizedType;
import org.jboss.jandex.Type;

import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.quarkiverse.opentelemetry.exporter.common.runtime.LateBoundSpanProcessor;
import io.quarkiverse.opentelemetry.exporter.gcp.runtime.GcpExporterConfig;
import io.quarkiverse.opentelemetry.exporter.gcp.runtime.GcpExporterProvider;
import io.quarkiverse.opentelemetry.exporter.gcp.runtime.GcpRecorder;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.BuildSteps;
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)
public class GcpExporterProcessor {
Expand All @@ -25,17 +39,39 @@ public boolean getAsBoolean() {
}

@BuildStep
AdditionalBeanBuildItem createBatchSpanProcessor() {
return AdditionalBeanBuildItem.builder()
.addBeanClass(GcpExporterProvider.class)
.setUnremovable().build();
void registerExternalExporter(BuildProducer<ExternalOtelExporterBuildItem> buildProducer) {
buildProducer.produce(new ExternalOtelExporterBuildItem("gcp"));
}

@BuildStep
NativeImageConfigBuildItem nativeImageConfiguration() {
NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder()
.addRuntimeReinitializedClass("com.google.protobuf.UnsafeUtil");
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)
void installBatchSpanProcessorForGcp(GcpRecorder recorder,
SyntheticBeanBuildItem installBatchSpanProcessorForGcp(GcpRecorder recorder,
LaunchModeBuildItem launchModeBuildItem,
GcpExporterConfig.GcpExporterRuntimeConfig runtimeConfig) {
recorder.installSpanProcessorForGcp(runtimeConfig, launchModeBuildItem.getLaunchMode());

return SyntheticBeanBuildItem.configure(LateBoundSpanProcessor.class)
.types(SpanProcessor.class)
.setRuntimeInit()
.scope(Singleton.class)
.unremovable()
.addInjectionPoint(ParameterizedType.create(DotName.createSimple(Instance.class),
new Type[] { ClassType.create(DotName.createSimple(SpanExporter.class.getName())) }, null))
.createWith(recorder.installSpanProcessorForGcp(runtimeConfig, launchModeBuildItem.getLaunchMode()))
.done();
}
}
56 changes: 30 additions & 26 deletions quarkus-opentelemetry-exporter-gcp/integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.opentelemetry.exporter</groupId>
Expand Down Expand Up @@ -98,29 +99,32 @@
</plugins>
</build>

<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.additional-build-args>-H:ReflectionConfigurationFiles=reflection-config.json</quarkus.native.additional-build-args>
</properties>
</profile>
</profiles>
<!-- FIXME native mode not working. The UdsNameResolverProvider is forced to be -->
<!-- initialized at run time with no good reason. This can be related to https://github.com/oracle/graal/pull/8230. -->

<!-- <profiles>-->
<!-- <profile>-->
<!-- <id>native-image</id>-->
<!-- <activation>-->
<!-- <property>-->
<!-- <name>native</name>-->
<!-- </property>-->
<!-- </activation>-->
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <artifactId>maven-surefire-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <skipTests>${native.surefire.skip}</skipTests>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<!-- <properties>-->
<!-- <skipITs>false</skipITs>-->
<!-- <quarkus.package.type>native</quarkus.package.type>-->
<!-- <quarkus.native.additional-build-args>-H:ReflectionConfigurationFiles=reflection-config.json</quarkus.native.additional-build-args>-->
<!-- </properties>-->
<!-- </profile>-->
<!-- </profiles>-->
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
quarkus.application.name=opentelemetry-exporter-gcp-integration-test
quarkus.application.version=999-SNAPSHOT

quarkus.opentelemetry.tracer.exporter.otlp.enabled=false

simple/mp-rest/url=${test.url}

quarkus.generate-code.grpc.scan-for-imports=all
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.quarkiverse.opentelemetry.exporter.it;

import org.junit.jupiter.api.Disabled;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
@Disabled("The UdsNameResolverProvider is forced to be initialized at run time with no good reason. " +
"This can be related to https://github.com/oracle/graal/pull/8230.")
public class GcpExporterIT extends GcpTraceBatchExporterTest {
}
21 changes: 6 additions & 15 deletions quarkus-opentelemetry-exporter-gcp/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>${gcp-opentelemetry.version}</version>
<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>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
Expand All @@ -58,6 +43,12 @@
<artifactId>gax</artifactId>
<version>${gax-grpc.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>${gcp-opentelemetry.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp-common</artifactId>
Expand Down

This file was deleted.

Loading
Loading