Skip to content

Commit

Permalink
Use AutoConfiguredOpenTelemetrySdkBuilderCustomizer for Azure (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti authored Sep 17, 2024
1 parent f1d5bb7 commit fd3662f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;

import io.quarkus.opentelemetry.runtime.AutoConfiguredOpenTelemetrySdkBuilderCustomizer;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Singleton;

Expand All @@ -18,15 +19,9 @@
import com.azure.core.http.vertx.VertxProvider;

import io.netty.handler.ssl.OpenSsl;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.quarkiverse.opentelemetry.exporter.azure.runtime.AzureEndpointSampler;
import io.quarkiverse.opentelemetry.exporter.azure.runtime.AzureExporterBuildConfig;
import io.quarkiverse.opentelemetry.exporter.azure.runtime.AzureExporterQuarkusRuntimeConfig;
import io.quarkiverse.opentelemetry.exporter.azure.runtime.AzureExporterRuntimeConfig;
import io.quarkiverse.opentelemetry.exporter.azure.runtime.AzureRecorder;
import io.quarkiverse.opentelemetry.exporter.common.runtime.LateBoundSpanProcessor;
import io.quarkiverse.opentelemetry.exporter.azure.runtime.*;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand Down Expand Up @@ -138,17 +133,20 @@ void registerExternalExporter(BuildProducer<ExternalOtelExporterBuildItem> build

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
SyntheticBeanBuildItem installBatchSpanProcessorForAzure(AzureRecorder recorder,
SyntheticBeanBuildItem openTelemetryCustomizer(AzureRecorder recorder,
AzureExporterRuntimeConfig runtimeConfig, AzureExporterQuarkusRuntimeConfig quarkusRuntimeConfig) {
return SyntheticBeanBuildItem.configure(LateBoundSpanProcessor.class)
.types(SpanProcessor.class)
return SyntheticBeanBuildItem.configure(AutoConfiguredOpenTelemetrySdkBuilderCustomizer.class)
.types(AutoConfigurationCustomizerProvider.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.createSpanProcessorForAzure(runtimeConfig, quarkusRuntimeConfig))
new Type[] {
ClassType.create(DotName.createSimple(AutoConfigurationCustomizerProvider.class.getName())) },
null))
.createWith(recorder.createAzureMonitorCustomizer(runtimeConfig, quarkusRuntimeConfig))
.done();

}

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

import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporterBuilder;

import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder;
import io.quarkus.opentelemetry.runtime.AutoConfiguredOpenTelemetrySdkBuilderCustomizer;

public class AzureMonitorCustomizer implements AutoConfiguredOpenTelemetrySdkBuilderCustomizer {

private final String azureConnectionString;

public AzureMonitorCustomizer(String azureConnectionString) {
this.azureConnectionString = azureConnectionString;
}

@Override
public void customize(AutoConfiguredOpenTelemetrySdkBuilder builder) {
new AzureMonitorExporterBuilder().connectionString(azureConnectionString)
.install(builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import java.util.function.Function;
import java.util.regex.Pattern;

import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporterBuilder;

import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.quarkiverse.opentelemetry.exporter.common.runtime.LateBoundSpanProcessor;
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.runtime.annotations.Recorder;

Expand All @@ -17,20 +12,14 @@ public class AzureRecorder {

public static final Pattern SEMI_COLON_PATTERN = Pattern.compile(";");

public Function<SyntheticCreationalContext<LateBoundSpanProcessor>, LateBoundSpanProcessor> createSpanProcessorForAzure(
public Function<SyntheticCreationalContext<AzureMonitorCustomizer>, AzureMonitorCustomizer> createAzureMonitorCustomizer(
AzureExporterRuntimeConfig runtimeConfig, AzureExporterQuarkusRuntimeConfig quarkusRuntimeConfig) {
return new Function<>() {
@Override
public LateBoundSpanProcessor apply(SyntheticCreationalContext<LateBoundSpanProcessor> context) {
try {
String azureConnectionString = findConnectionString(runtimeConfig, quarkusRuntimeConfig);
SpanExporter azureSpanExporter = new AzureMonitorExporterBuilder()
.connectionString(azureConnectionString)
.buildTraceExporter();
return new LateBoundSpanProcessor(BatchSpanProcessor.builder(azureSpanExporter).build());
} catch (IllegalArgumentException iae) {
throw new IllegalStateException("Unable to install OTel Azure Exporter", iae);
}
public AzureMonitorCustomizer apply(
SyntheticCreationalContext<AzureMonitorCustomizer> objectSyntheticCreationalContext) {
String azureConnectionString = findConnectionString(runtimeConfig, quarkusRuntimeConfig);
return new AzureMonitorCustomizer(azureConnectionString);
}
};
}
Expand Down

0 comments on commit fd3662f

Please sign in to comment.