Skip to content

Commit

Permalink
High priority defaults for OtlpExporterRuntimeConfig
Browse files Browse the repository at this point in the history
(cherry picked from commit 883b1ed)
  • Loading branch information
radcortez authored and gsmet committed Sep 3, 2024
1 parent 35c53b6 commit d5d3779
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.*;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem;
import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig;
import io.quarkus.opentelemetry.runtime.config.build.exporter.OtlpExporterBuildConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfigBuilder;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
import io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterRecorder;
import io.quarkus.opentelemetry.runtime.exporter.otlp.tracing.LateBoundBatchSpanProcessor;
Expand Down Expand Up @@ -59,6 +61,11 @@ public boolean getAsBoolean() {
}
}

@BuildStep
void config(BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilderProducer) {
runTimeConfigBuilderProducer.produce(new RunTimeConfigBuilderBuildItem(OtlpExporterConfigBuilder.class));
}

@SuppressWarnings("deprecation")
@BuildStep(onlyIf = OtlpExporterProcessor.OtlpTracingExporterEnabled.class)
@Record(ExecutionTime.RUNTIME_INIT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package io.quarkus.opentelemetry.runtime.config;
package io.quarkus.opentelemetry.runtime.config.runtime.exporter;

import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfig.DEFAULT_GRPC_BASE_URI;
import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfig.Protocol.GRPC;

import java.util.HashMap;
import java.util.Map;

import io.quarkus.runtime.configuration.ConfigBuilder;
import io.smallrye.config.FallbackConfigSourceInterceptor;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

public class OpenTelemetryConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
/**
* Adds fallbacks to {@link OtlpExporterRuntimeConfig#traces()} and {@link OtlpExporterRuntimeConfig#metrics()} from
* the base configuration {@link OtlpExporterRuntimeConfig}. The goal is to fallback specific properties from either
* <code>tracer</code> or <code>metrics</code> to their parent configuration. For instance, if there is no value for
* <code>quarkus.otel.exporter.otlp.traces.endpoint</code> it fallbacks to
* <code>quarkus.otel.exporter.otlp.endpoint</code>.
* <p>
* Defaults are set using the {@link SmallRyeConfigBuilder#withDefaultValue(String, String)}, instead of
* {@link io.smallrye.config.WithDefault} because the mapping {@link OtlpExporterConfig} is shared between base
* (unnamed), <code>traces</code>, and <code>metrics</code>, which means that every path would always have a default,
* and it won't be possible to fallback from the specific configuration to the base configuration.
* <p>
* This builder is only set to customize the runtime configuration since the mapping {@link OtlpExporterRuntimeConfig}
* is only for runtime. The builder executes with a very high priority to ensure that it sets the default
* configuration early in the config setup to allow other configurations to override it (like Dev Services).
*/
public class OtlpExporterConfigBuilder implements ConfigBuilder {
@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
// Main defaults
builder.withDefaultValue("quarkus.otel.exporter.otlp.endpoint", DEFAULT_GRPC_BASE_URI);
builder.withDefaultValue("quarkus.otel.exporter.otlp.protocol", GRPC);
Expand Down Expand Up @@ -60,6 +76,11 @@ public void configBuilder(final SmallRyeConfigBuilder builder) {
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.host", "quarkus.otel.exporter.otlp.proxy-options.host");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.port", "quarkus.otel.exporter.otlp.proxy-options.port");

builder.withInterceptors(new FallbackConfigSourceInterceptor(fallbacks));
return builder.withInterceptors(new FallbackConfigSourceInterceptor(fallbacks));
}

@Override
public int priority() {
return Integer.MIN_VALUE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.junit.jupiter.api.Test;

import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfigBuilder;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterMetricsConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig;
Expand All @@ -39,7 +40,7 @@ void fromBase() {
baseExporterConfig.put("quarkus.otel.exporter.otlp.proxy-options.port", "9999");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.withCustomizers(new OpenTelemetryConfigBuilderCustomizer())
.withCustomizers(builder -> new OtlpExporterConfigBuilder().configBuilder(builder))
.withMapping(OtlpExporterRuntimeConfig.class)
.withDefaultValues(baseExporterConfig)
.build();
Expand Down Expand Up @@ -160,7 +161,7 @@ void overrideTraces() {
tracesExporterConfig.put("quarkus.otel.exporter.otlp.traces.proxy-options.port", "6666");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.withCustomizers(new OpenTelemetryConfigBuilderCustomizer())
.withCustomizers(builder -> new OtlpExporterConfigBuilder().configBuilder(builder))
.withMapping(OtlpExporterRuntimeConfig.class)
.withDefaultValues(baseExporterConfig)
.withDefaultValues(tracesExporterConfig)
Expand Down

0 comments on commit d5d3779

Please sign in to comment.