Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry traces and metrics config fallback to base #42814

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder whether this should be

quarkus.put(propertyName.substring(8), config.getValue(propertyName, String.class));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is OK.

We now provide relocations and fallbacks from specific path trees quarkus.otel.exporter.otlp.traces and quarkus.otel.exporter.otlp.metrics to quarkus.otel.exporter.otlp. The relocations and fallbacks have to include the mapping names to work correctly. Because we don't know if we will get the specific or the base configuration, the properties are marked as Optional in the mapping interface.

In this code, we copy the quarkus properties to the otel properties. Because we now have extra names that may not have a value, using getValue will give an error when looking up the configuration. Before, only the property names that contained values were available (the ones defined by the user or defaults). To avoid that error, we now have to use getConfigValue, which, on the other hand, does not give an error when you have an expression that cannot be expanded, so in such cases, we force the getValue to give that error.

}
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
Loading