Skip to content

Commit

Permalink
Allow default exporter with additional Quarkiverse exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Balau committed Oct 18, 2023
1 parent 996730b commit 5db75e3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void createBatchSpanProcessor(OTelExporterRecorder recorder,
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
if (!exporterRuntimeConfig.activateDefaultExporter() && !externalOtelExporterBuildItem.isEmpty()) {
// unless explicitly configured, if there is an external exporter we don't want to create the default one
return;
}
syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class OtlpExporterConfigTest {
.withEmptyApplication()
.overrideConfigKey("otel.traces.exporter", "cdi")
.overrideConfigKey("otel.exporter.otlp.traces.protocol", "http/protobuf")
.overrideConfigKey("quarkus.otel.exporter.otlp.default.enable", "true")
.overrideConfigKey("quarkus.opentelemetry.tracer.exporter.otlp.endpoint", "http://localhost ")
.overrideConfigKey("quarkus.otel.bsp.schedule.delay", "50")
.overrideConfigKey("quarkus.otel.bsp.export.timeout", "PT1S");
Expand All @@ -28,5 +29,6 @@ public class OtlpExporterConfigTest {
void config() {
assertTrue(config.traces().legacyEndpoint().isPresent());
assertEquals("http://localhost", config.traces().legacyEndpoint().get().trim());
assertTrue(config.activateDefaultExporter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

/**
* From <a href=
Expand All @@ -27,6 +28,16 @@ public interface OtlpExporterRuntimeConfig {
@WithDefault(DEFAULT_GRPC_BASE_URI)
Optional<String> endpoint();

/**
* If true, the default OpenTelemetry exporter will always be instantiated, even when other
* exporters are present.
* <p>
* Defaults to <code>false</code>.
*/
@WithName("default.enable")
@WithDefault("false")
boolean activateDefaultExporter();

/**
* OTLP traces exporter configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -173,17 +174,27 @@ private URI getBaseUri(OtlpExporterRuntimeConfig exporterRuntimeConfig) {
}

static String resolveEndpoint(final OtlpExporterRuntimeConfig runtimeConfig) {
String endpoint = runtimeConfig.traces().legacyEndpoint()
.filter(OTelExporterRecorder::excludeDefaultEndpoint)
.orElse(runtimeConfig.traces().endpoint()
.filter(OTelExporterRecorder::excludeDefaultEndpoint)
.orElse(runtimeConfig.endpoint()
.filter(OTelExporterRecorder::excludeDefaultEndpoint)
.orElse(DEFAULT_GRPC_BASE_URI)));
String endpoint = excludeDefaultEndpoint(
runtimeConfig.traces().legacyEndpoint(),
runtimeConfig)
.orElse(
excludeDefaultEndpoint(
runtimeConfig.traces().endpoint(),
runtimeConfig)
.orElse(
excludeDefaultEndpoint(
runtimeConfig.endpoint(),
runtimeConfig).orElse(DEFAULT_GRPC_BASE_URI)));

return endpoint.trim();
}

private static boolean excludeDefaultEndpoint(String endpoint) {
private static Optional<String> excludeDefaultEndpoint(Optional<String> endpoint, OtlpExporterRuntimeConfig runtimeConfig) {
return endpoint
.filter(uri -> !runtimeConfig.activateDefaultExporter() && OTelExporterRecorder.isDefaultEndpoint(uri));
}

private static boolean isDefaultEndpoint(String endpoint) {
return !DEFAULT_GRPC_BASE_URI.equals(endpoint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public Optional<String> endpoint() {
return Optional.ofNullable(exporterGlobal);
}

@Override
public boolean activateDefaultExporter() {
return false;
}

@Override
public OtlpExporterTracesConfig traces() {
return new OtlpExporterTracesConfig() {
Expand Down

0 comments on commit 5db75e3

Please sign in to comment.