diff --git a/docs/src/main/asciidoc/opentelemetry.adoc b/docs/src/main/asciidoc/opentelemetry.adoc index 5fc87576d2279..41160b625ddd0 100644 --- a/docs/src/main/asciidoc/opentelemetry.adoc +++ b/docs/src/main/asciidoc/opentelemetry.adoc @@ -429,7 +429,7 @@ Write the SPI loader text file at `resources/META-INF/services` with name `io.op Then activate on the configuration: [source,properties] ---- -quarkus.opentelemetry.tracer.sampler=custom-spi-sampler +quarkus.otel.traces.sampler=custom-spi-sampler ---- As you can see, CDI is much simpler to work with. diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java index 8ccf190cfdfa4..d1e2f973f3c96 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java @@ -1,7 +1,6 @@ package io.quarkus.opentelemetry.deployment.exporter.otlp; import static io.quarkus.opentelemetry.runtime.config.build.ExporterType.Constants.CDI_VALUE; -import static io.quarkus.opentelemetry.runtime.config.build.ExporterType.Constants.OTLP_VALUE; import java.util.function.BooleanSupplier; @@ -23,16 +22,14 @@ public class OtlpExporterProcessor { static class OtlpExporterEnabled implements BooleanSupplier { - OtlpExporterBuildConfig exporBuildConfig; + OtlpExporterBuildConfig exportBuildConfig; OtelBuildConfig otelBuildConfig; public boolean getAsBoolean() { return otelBuildConfig.enabled && otelBuildConfig.traces.enabled.orElse(Boolean.TRUE) && - (otelBuildConfig.traces.exporter.contains(OTLP_VALUE) || - otelBuildConfig.traces.exporter.contains(CDI_VALUE)) - && - exporBuildConfig.enabled; + otelBuildConfig.traces.exporter.contains(CDI_VALUE) && + exportBuildConfig.enabled; } } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java index 8e2562db31669..6ba48de1f1276 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorder.java @@ -1,5 +1,6 @@ package io.quarkus.opentelemetry.runtime.exporter.otlp; +import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig.Constants.DEFAULT_GRPC_BASE_URI; import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig.Protocol.HTTP_PROTOBUF; import java.util.function.Consumer; @@ -20,17 +21,22 @@ @Recorder public class OtlpRecorder { - static String resolveEndpoint(final LaunchMode launchMode, final OtlpExporterRuntimeConfig runtimeConfig) { + + static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) { String endpoint = runtimeConfig.traces.legacyEndpoint + .filter(OtlpRecorder::excludeDefaultEndpoint) .orElse(runtimeConfig.traces.endpoint - .orElse(runtimeConfig.endpoint.orElse(""))); - if (launchMode == LaunchMode.DEVELOPMENT && endpoint.isEmpty()) { - // Default the endpoint for development only - endpoint = OtlpExporterRuntimeConfig.Constants.DEFAULT_GRPC_BASE_URI; - } + .filter(OtlpRecorder::excludeDefaultEndpoint) + .orElse(runtimeConfig.endpoint + .filter(OtlpRecorder::excludeDefaultEndpoint) + .orElse(DEFAULT_GRPC_BASE_URI))); return endpoint.trim(); } + private static boolean excludeDefaultEndpoint(String endpoint) { + return !DEFAULT_GRPC_BASE_URI.equals(endpoint); + } + public void installBatchSpanProcessorForOtlp( OtelRuntimeConfig otelRuntimeConfig, OtlpExporterRuntimeConfig exporterRuntimeConfig, @@ -39,7 +45,7 @@ public void installBatchSpanProcessorForOtlp( if (otelRuntimeConfig.sdkDisabled) { return; } - String endpoint = resolveEndpoint(launchMode, exporterRuntimeConfig).trim(); + String endpoint = resolveEndpoint(exporterRuntimeConfig).trim(); // Only create the OtlpGrpcSpanExporter if an endpoint was set in runtime config if (endpoint.length() > 0) { diff --git a/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java b/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java index 3e7f74c86eb4f..72fbbf653082c 100644 --- a/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java +++ b/extensions/opentelemetry/runtime/src/test/java/io/quarkus/opentelemetry/runtime/exporter/otlp/OtlpRecorderTest.java @@ -1,5 +1,6 @@ package io.quarkus.opentelemetry.runtime.exporter.otlp; +import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig.Constants.DEFAULT_GRPC_BASE_URI; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Optional; @@ -8,50 +9,58 @@ import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig; -import io.quarkus.runtime.LaunchMode; class OtlpRecorderTest { @Test public void resolveEndpoint_legacyWins() { assertEquals("http://localhost:1111/", - OtlpRecorder.resolveEndpoint(LaunchMode.NORMAL, createOtlpExporterRuntimeConfig( - "http://localhost:4317/", + OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + DEFAULT_GRPC_BASE_URI, "http://localhost:1111/", "http://localhost:2222/"))); } @Test - public void resolveEndpoint_legacyTraceWins() { + public void resolveEndpoint_newWins() { assertEquals("http://localhost:2222/", - OtlpRecorder.resolveEndpoint(LaunchMode.NORMAL, createOtlpExporterRuntimeConfig( - "http://localhost:4317/", - null, + OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + "http://localhost:1111/", + DEFAULT_GRPC_BASE_URI, "http://localhost:2222/"))); } @Test - public void resolveEndpoint_legacyGlobalWins() { - assertEquals("http://localhost:4317/", - OtlpRecorder.resolveEndpoint(LaunchMode.NORMAL, createOtlpExporterRuntimeConfig( - "http://localhost:4317/", - null, - null))); + public void resolveEndpoint_globalWins() { + assertEquals("http://localhost:1111/", + OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + "http://localhost:1111/", + DEFAULT_GRPC_BASE_URI, + DEFAULT_GRPC_BASE_URI))); } @Test - public void resolveEndpoint_testIsSet() { - assertEquals("http://localhost:4317/", - OtlpRecorder.resolveEndpoint(LaunchMode.DEVELOPMENT, createOtlpExporterRuntimeConfig( + public void resolveEndpoint_legacyTraceWins() { + assertEquals("http://localhost:2222/", + OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + DEFAULT_GRPC_BASE_URI, null, + "http://localhost:2222/"))); + } + + @Test + public void resolveEndpoint_legacyGlobalWins() { + assertEquals(DEFAULT_GRPC_BASE_URI, + OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( + DEFAULT_GRPC_BASE_URI, null, null))); } @Test - public void resolveEndpoint_NothingSet() { - assertEquals("", - OtlpRecorder.resolveEndpoint(LaunchMode.NORMAL, createOtlpExporterRuntimeConfig( + public void resolveEndpoint_testIsSet() { + assertEquals(DEFAULT_GRPC_BASE_URI, + OtlpRecorder.resolveEndpoint(createOtlpExporterRuntimeConfig( null, null, null)));