Skip to content

Commit

Permalink
support external exporters in CDI
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Oct 16, 2023
1 parent 841b3a1 commit 2632e1c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.opentelemetry.deployment.exporter.otlp;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Build item to be used by Quarkiverse exporters to register themselves as an external exporter.
*/
final public class ExternalOtelExporterBuildItem extends MultiBuildItem {
final private String exporterName;

public ExternalOtelExporterBuildItem(String exporterName) {
this.exporterName = exporterName;
}

public String getExporterName() {
return exporterName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.quarkus.opentelemetry.runtime.config.build.ExporterType.Constants.CDI_VALUE;

import java.util.List;
import java.util.function.BooleanSupplier;

import jakarta.enterprise.inject.Instance;
Expand All @@ -27,7 +28,7 @@
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
import io.quarkus.opentelemetry.runtime.exporter.otlp.EndUserSpanProcessor;
import io.quarkus.opentelemetry.runtime.exporter.otlp.LateBoundBatchSpanProcessor;
import io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpRecorder;
import io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterRecorder;
import io.quarkus.runtime.TlsConfig;
import io.quarkus.vertx.core.deployment.CoreVertxBuildItem;

Expand Down Expand Up @@ -60,12 +61,18 @@ void createEndUserSpanProcessor(
@SuppressWarnings("deprecation")
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
SyntheticBeanBuildItem createBatchSpanProcessor(OtlpRecorder recorder,
void createBatchSpanProcessor(OTelExporterRecorder recorder,
OTelRuntimeConfig otelRuntimeConfig,
OtlpExporterRuntimeConfig exporterRuntimeConfig,
TlsConfig tlsConfig,
CoreVertxBuildItem vertxBuildItem) {
return SyntheticBeanBuildItem
CoreVertxBuildItem vertxBuildItem,
List<ExternalOtelExporterBuildItem> externalOtelExporterBuildItem,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer) {
if (!externalOtelExporterBuildItem.isEmpty()) {
// if there is an external exporter, we don't want to create the default one
return;
}
syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem
.configure(LateBoundBatchSpanProcessor.class)
.types(SpanProcessor.class)
.setRuntimeInit()
Expand All @@ -75,7 +82,6 @@ SyntheticBeanBuildItem createBatchSpanProcessor(OtlpRecorder recorder,
new Type[] { ClassType.create(DotName.createSimple(SpanExporter.class.getName())) }, null))
.createWith(recorder.batchSpanProcessorForOtlp(otelRuntimeConfig, exporterRuntimeConfig, tlsConfig,
vertxBuildItem.getVertx()))
.done();

.done());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

@SuppressWarnings("deprecation")
@Recorder
public class OtlpRecorder {
public class OTelExporterRecorder {

public Function<SyntheticCreationalContext<LateBoundBatchSpanProcessor>, LateBoundBatchSpanProcessor> batchSpanProcessorForOtlp(
OTelRuntimeConfig otelRuntimeConfig,
Expand Down Expand Up @@ -174,11 +174,11 @@ private URI getBaseUri(OtlpExporterRuntimeConfig exporterRuntimeConfig) {

static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) {
String endpoint = runtimeConfig.traces().legacyEndpoint()
.filter(OtlpRecorder::excludeDefaultEndpoint)
.filter(OTelExporterRecorder::excludeDefaultEndpoint)
.orElse(runtimeConfig.traces().endpoint()
.filter(OtlpRecorder::excludeDefaultEndpoint)
.filter(OTelExporterRecorder::excludeDefaultEndpoint)
.orElse(runtimeConfig.endpoint()
.filter(OtlpRecorder::excludeDefaultEndpoint)
.filter(OTelExporterRecorder::excludeDefaultEndpoint)
.orElse(DEFAULT_GRPC_BASE_URI)));
return endpoint.trim();
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private void configureTLS(HttpClientOptions options) {
options.setKeyCertOptions(toPemKeyCertOptions());
options.setPemTrustOptions(toPemTrustOptions());

if (OtlpExporterUtil.isHttps(baseUri)) {
if (OTelExporterUtil.isHttps(baseUri)) {
options.setSsl(true);
options.setUseAlpn(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.net.URI;
import java.util.Locale;

final class OtlpExporterUtil {
final class OTelExporterUtil {

private OtlpExporterUtil() {
private OTelExporterUtil() {
}

static int getPort(URI uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class VertxGrpcExporter implements SpanExporter {
Vertx vertx) {
this.type = type;
this.exporterMetrics = ExporterMetrics.createGrpcOkHttp(exporterName, type, meterProviderSupplier);
this.server = SocketAddress.inetSocketAddress(OtlpExporterUtil.getPort(grpcBaseUri), grpcBaseUri.getHost());
this.server = SocketAddress.inetSocketAddress(OTelExporterUtil.getPort(grpcBaseUri), grpcBaseUri.getHost());
this.compressionEnabled = compressionEnabled;
this.headers = headersMap;
var httpClientOptions = new HttpClientOptions()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.quarkus.opentelemetry.runtime.exporter.otlp;

import static io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpExporterUtil.getPort;
import static io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterUtil.getPort;

import java.io.IOException;
import java.io.OutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OtlpExporterProviderTest {
@Test
public void resolveEndpoint_legacyWins() {
assertEquals("http://localhost:1111/",
OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
DEFAULT_GRPC_BASE_URI,
"http://localhost:1111/",
"http://localhost:2222/")));
Expand All @@ -27,7 +27,7 @@ public void resolveEndpoint_legacyWins() {
@Test
public void resolveEndpoint_newWins() {
assertEquals("http://localhost:2222/",
OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
"http://localhost:1111/",
DEFAULT_GRPC_BASE_URI,
"http://localhost:2222/")));
Expand All @@ -36,7 +36,7 @@ public void resolveEndpoint_newWins() {
@Test
public void resolveEndpoint_globalWins() {
assertEquals("http://localhost:1111/",
OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
"http://localhost:1111/",
DEFAULT_GRPC_BASE_URI,
DEFAULT_GRPC_BASE_URI)));
Expand All @@ -45,7 +45,7 @@ public void resolveEndpoint_globalWins() {
@Test
public void resolveEndpoint_legacyTraceWins() {
assertEquals("http://localhost:2222/",
OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
DEFAULT_GRPC_BASE_URI,
null,
"http://localhost:2222/")));
Expand All @@ -54,7 +54,7 @@ public void resolveEndpoint_legacyTraceWins() {
@Test
public void resolveEndpoint_legacyGlobalWins() {
assertEquals(DEFAULT_GRPC_BASE_URI,
OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
DEFAULT_GRPC_BASE_URI,
null,
null)));
Expand All @@ -63,7 +63,7 @@ public void resolveEndpoint_legacyGlobalWins() {
@Test
public void resolveEndpoint_testIsSet() {
assertEquals(DEFAULT_GRPC_BASE_URI,
OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
OTelExporterRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig(
null,
null,
null)));
Expand Down

0 comments on commit 2632e1c

Please sign in to comment.