Skip to content

Commit

Permalink
Fix instantiation of the exporters for Quarkus v3.2+, update parent a…
Browse files Browse the repository at this point in the history
…nd fix native mode
  • Loading branch information
brunobat committed Jan 11, 2024
1 parent 8231c45 commit 0c92e49
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 151 deletions.
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 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/
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,41 @@ 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")
.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)
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();
}
}
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
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.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.quarkiverse.opentelemetry.exporter.gcp.runtime;

import java.io.IOException;

import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.CDI;
import java.util.function.Function;

import com.google.cloud.opentelemetry.trace.TestTraceConfigurationBuilder;
import com.google.cloud.opentelemetry.trace.TraceConfiguration;
Expand All @@ -13,40 +11,51 @@
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.quarkiverse.opentelemetry.exporter.common.runtime.LateBoundSpanProcessor;
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class GcpRecorder {
public void installSpanProcessorForGcp(GcpExporterConfig.GcpExporterRuntimeConfig runtimeConfig, LaunchMode launchMode) {
if (launchMode != LaunchMode.TEST && runtimeConfig.endpoint.isEmpty()) {
try {
configureTraceExporter(runtimeConfig);
} catch (IOException e) {
throw new RuntimeException("Unable to initialize GCP TraceExporter.", e);
}
} else {
TraceConfiguration.Builder builder = TestTraceConfigurationBuilder.buildTestTraceConfiguration();

if (runtimeConfig.endpoint.isPresent() && runtimeConfig.endpoint.get().trim().length() > 0) {
builder.setTraceServiceEndpoint(runtimeConfig.endpoint.get());
}

TraceConfiguration config = builder.build();
try {
if (runtimeConfig.cloudrun) {
configureSimpleSpanExporter(config);
public Function<SyntheticCreationalContext<LateBoundSpanProcessor>, LateBoundSpanProcessor> installSpanProcessorForGcp(
GcpExporterConfig.GcpExporterRuntimeConfig runtimeConfig,
LaunchMode launchMode) {
return new Function<>() {
@Override
public LateBoundSpanProcessor apply(
SyntheticCreationalContext<LateBoundSpanProcessor> lateBoundSpanProcessorSyntheticCreationalContext) {

if (launchMode != LaunchMode.TEST && runtimeConfig.endpoint.isEmpty()) {
try {
return configureTraceExporter(runtimeConfig);
} catch (IOException e) {
throw new RuntimeException("Unable to initialize GCP TraceExporter.", e);
}
} else {
configureBatchSpanExporter(config);
TraceConfiguration.Builder builder = TestTraceConfigurationBuilder.buildTestTraceConfiguration();

if (runtimeConfig.endpoint.isPresent() && runtimeConfig.endpoint.get().trim().length() > 0) {
builder.setTraceServiceEndpoint(runtimeConfig.endpoint.get());
}

TraceConfiguration config = builder.build();
try {
if (runtimeConfig.cloudrun) {
return configureSimpleSpanExporter(config);
} else {
return configureBatchSpanExporter(config);
}
} catch (IOException e) {
throw new RuntimeException("Unable to initialize GCP TraceExporter.", e);
}
}
} catch (IOException e) {
throw new RuntimeException("Unable to initialize GCP TraceExporter.", e);
}
}

};
}

private void configureTraceExporter(GcpExporterConfig.GcpExporterRuntimeConfig runtimeConfig) throws IOException {
private LateBoundSpanProcessor configureTraceExporter(GcpExporterConfig.GcpExporterRuntimeConfig runtimeConfig)
throws IOException {
TraceConfiguration.Builder builder = TraceConfiguration.builder();

if (runtimeConfig.projectid.isPresent() && runtimeConfig.projectid.get().trim().length() > 0) {
Expand All @@ -56,29 +65,21 @@ private void configureTraceExporter(GcpExporterConfig.GcpExporterRuntimeConfig r
TraceConfiguration traceConfig = builder.build();
// Initialize GCP TraceExporter default configuration
if (runtimeConfig.cloudrun) {
configureSimpleSpanExporter(traceConfig);
return configureSimpleSpanExporter(traceConfig);
} else {
configureBatchSpanExporter(traceConfig);
return configureBatchSpanExporter(traceConfig);
}
}

private void configureBatchSpanExporter(TraceConfiguration config) throws IOException {
BatchSpanProcessor batchSpanProcessor = BatchSpanProcessor.builder(TraceExporter.createWithConfiguration(config))
private LateBoundSpanProcessor configureBatchSpanExporter(TraceConfiguration config) throws IOException {
BatchSpanProcessor batchSpanProcessor = BatchSpanProcessor
.builder(TraceExporter.createWithConfiguration(config))
.build();

LateBoundSpanProcessor delayedProcessor = CDI.current()
.select(LateBoundSpanProcessor.class, Any.Literal.INSTANCE).get();

delayedProcessor.setSpanProcessorDelegate(batchSpanProcessor);
return new LateBoundSpanProcessor(batchSpanProcessor);
}

private void configureSimpleSpanExporter(TraceConfiguration config) throws IOException {
TraceExporter traceExporter = TraceExporter.createWithConfiguration(config);
SpanProcessor spanProcessor = SimpleSpanProcessor.create(traceExporter);

LateBoundSpanProcessor delayedProcessor = CDI.current()
.select(LateBoundSpanProcessor.class, Any.Literal.INSTANCE).get();

delayedProcessor.setSpanProcessorDelegate(spanProcessor);
private LateBoundSpanProcessor configureSimpleSpanExporter(TraceConfiguration config) throws IOException {
SpanProcessor spanProcessor = SimpleSpanProcessor.create(TraceExporter.createWithConfiguration(config));
return new LateBoundSpanProcessor(spanProcessor);
}
}
Loading

0 comments on commit 0c92e49

Please sign in to comment.