Skip to content

Commit

Permalink
OpenTelemetry traces and metrics config fallback to base
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Aug 27, 2024
1 parent 03b025c commit a85662d
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ private Map<String, String> getOtelConfigs() {
// load new properties
for (String propertyName : config.getPropertyNames()) {
if (propertyName.startsWith("quarkus.otel.")) {
String value = config.getValue(propertyName, String.class);
if (propertyName.endsWith("timeout") || propertyName.endsWith("delay")) {
value = OTelDurationConverter.INSTANCE.convert(value);
ConfigValue value = config.getConfigValue(propertyName);
if (value.getValue() != null) {
if (propertyName.endsWith("timeout") || propertyName.endsWith("delay")) {
quarkus.put(propertyName.substring(8),
OTelDurationConverter.INSTANCE.convert(value.getValue()));
} else {
quarkus.put(propertyName.substring(8), value.getValue());
}
} else if (value.getValue() == null && value.getRawValue() != null) {
config.getValue(propertyName, String.class);
}
quarkus.put(propertyName.substring(8), value);
} else if (propertyName.startsWith("otel.")) {
ConfigValue value = config.getConfigValue(propertyName);
if (value.getValue() != null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.quarkus.opentelemetry.runtime.config;

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.smallrye.config.FallbackConfigSourceInterceptor;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

public class OpenTelemetryConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
@Override
public void 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);
builder.withDefaultValue("quarkus.otel.exporter.otlp.timeout", "10s");
builder.withDefaultValue("quarkus.otel.exporter.otlp.proxy-options.enabled", "false");

Map<String, String> fallbacks = new HashMap<>(30);
// Traces
fallbacks.put("quarkus.otel.exporter.otlp.traces.endpoint", "quarkus.otel.exporter.otlp.endpoint");
fallbacks.put("quarkus.otel.exporter.otlp.traces.headers", "quarkus.otel.exporter.otlp.headers");
fallbacks.put("quarkus.otel.exporter.otlp.traces.compression", "quarkus.otel.exporter.otlp.compression");
fallbacks.put("quarkus.otel.exporter.otlp.traces.timeout", "quarkus.otel.exporter.otlp.timeout");
fallbacks.put("quarkus.otel.exporter.otlp.traces.protocol", "quarkus.otel.exporter.otlp.protocol");
fallbacks.put("quarkus.otel.exporter.otlp.traces.key-cert.keys", "quarkus.otel.exporter.otlp.key-cert.keys");
fallbacks.put("quarkus.otel.exporter.otlp.traces.key-cert.certs", "quarkus.otel.exporter.otlp.key-cert.certs");
fallbacks.put("quarkus.otel.exporter.otlp.traces.trust-cert.certs", "quarkus.otel.exporter.otlp.trust-cert.certs");
fallbacks.put("quarkus.otel.exporter.otlp.traces.tls-configuration-name",
"quarkus.otel.exporter.otlp.tls-configuration-name");
fallbacks.put("quarkus.otel.exporter.otlp.traces.proxy-options.enabled",
"quarkus.otel.exporter.otlp.proxy-options.enabled");
fallbacks.put("quarkus.otel.exporter.otlp.traces.proxy-options.username",
"quarkus.otel.exporter.otlp.proxy-options.username");
fallbacks.put("quarkus.otel.exporter.otlp.traces.proxy-options.password",
"quarkus.otel.exporter.otlp.proxy-options.password");
fallbacks.put("quarkus.otel.exporter.otlp.traces.proxy-options.host", "quarkus.otel.exporter.otlp.proxy-options.host");
fallbacks.put("quarkus.otel.exporter.otlp.traces.proxy-options.port", "quarkus.otel.exporter.otlp.proxy-options.port");

// Metrics
fallbacks.put("quarkus.otel.exporter.otlp.metrics.endpoint", "quarkus.otel.exporter.otlp.endpoint");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.headers", "quarkus.otel.exporter.otlp.headers");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.compression", "quarkus.otel.exporter.otlp.compression");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.timeout", "quarkus.otel.exporter.otlp.timeout");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.protocol", "quarkus.otel.exporter.otlp.protocol");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.key-cert.keys", "quarkus.otel.exporter.otlp.key-cert.keys");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.key-cert.certs", "quarkus.otel.exporter.otlp.key-cert.certs");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.trust-cert.certs", "quarkus.otel.exporter.otlp.trust-cert.certs");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.tls-configuration-name",
"quarkus.otel.exporter.otlp.tls-configuration-name");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.enabled",
"quarkus.otel.exporter.otlp.proxy-options.enabled");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.username",
"quarkus.otel.exporter.otlp.proxy-options.username");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.password",
"quarkus.otel.exporter.otlp.proxy-options.password");
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.Optional;
import java.util.OptionalInt;

import io.smallrye.config.WithDefault;
import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.configuration.DurationConverter;
import io.smallrye.config.WithConverter;
import io.smallrye.config.WithName;

public interface OtlpExporterConfig {
Expand All @@ -24,7 +26,7 @@ public interface OtlpExporterConfig {
* If protocol is `http/protobuf` the version and signal will be appended to the path (e.g. v1/traces or v1/metrics)
* and the default port will be {@value OtlpExporterRuntimeConfig#DEFAULT_HTTP_BASE_URI}.
*/
@WithDefault(DEFAULT_GRPC_BASE_URI)
@ConfigDocDefault(DEFAULT_GRPC_BASE_URI)
Optional<String> endpoint();

/**
Expand Down Expand Up @@ -56,7 +58,8 @@ public interface OtlpExporterConfig {
* `quarkus.otel.exporter.otlp.<signal-type>.timeout` where <signal-type> is one of the supported signal types,
* like `traces` or `metrics`.
*/
@WithDefault("10s")
@ConfigDocDefault("10s")
@WithConverter(DurationConverter.class)
Duration timeout();

/**
Expand All @@ -71,7 +74,7 @@ public interface OtlpExporterConfig {
* `quarkus.otel.exporter.otlp.<signal-type>.protocol` where <signal-type> is one of the supported signal types,
* like `traces` or `metrics`.
*/
@WithDefault(OtlpExporterConfig.Protocol.GRPC)
@ConfigDocDefault(OtlpExporterConfig.Protocol.GRPC)
Optional<String> protocol();

/**
Expand Down Expand Up @@ -126,7 +129,7 @@ interface ProxyConfig {
* types,
* like `traces` or `metrics`.
*/
@WithDefault("false")
@ConfigDocDefault("false")
boolean enabled();

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.opentelemetry.runtime.config.OpenTelemetryConfigBuilderCustomizer

This file was deleted.

Loading

0 comments on commit a85662d

Please sign in to comment.