Skip to content

Commit

Permalink
Log hadler on by default. Build step only if LogsEnabled. Config inte…
Browse files Browse the repository at this point in the history
…rceptor tweaks
  • Loading branch information
brunobat committed Aug 21, 2024
1 parent 4d09b9d commit c52c74f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package io.quarkus.opentelemetry.deployment.logging;

import java.util.function.BooleanSupplier;
import java.util.function.Function;

import io.quarkus.agroal.spi.OpenTelemetryInitBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.BuildSteps;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig;
import io.quarkus.opentelemetry.runtime.logs.OpenTelemetryLogConfig;
import io.quarkus.opentelemetry.runtime.logs.OpenTelemetryLogRecorder;

@BuildSteps(onlyIf = LogHandlerProcessor.LogsEnabled.class)
class LogHandlerProcessor {

@BuildStep
Expand All @@ -17,4 +23,19 @@ class LogHandlerProcessor {
LogHandlerBuildItem build(OpenTelemetryLogRecorder recorder, OpenTelemetryLogConfig config) {
return new LogHandlerBuildItem(recorder.initializeHandler(config));
}

public static class LogsEnabled implements BooleanSupplier {
OTelBuildConfig otelBuildConfig;

public boolean getAsBoolean() {
return otelBuildConfig.logs().enabled()
.map(new Function<Boolean, Boolean>() {
@Override
public Boolean apply(Boolean enabled) {
return otelBuildConfig.enabled() && enabled;
}
})
.orElseGet(() -> otelBuildConfig.enabled());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class HierarchicalOTelConnectionConfigInterceptor extends FallbackConfigS
static final String BASE = "quarkus.otel.exporter.otlp.";
static final String TRACES = BASE + "traces.";
static final String METRICS = BASE + "metrics.";
static final String LOGS = BASE + "logs.";

private static final MappingFunction mappingFunction = new MappingFunction();

Expand Down Expand Up @@ -86,6 +87,12 @@ public String apply(String name) {
return BASE + property;
}
}
if (name.startsWith(LOGS)) {
String property = name.substring(LOGS.length());
if (PROPERTY_NAMES.contains(property)) {
return BASE + property;
}
}
return name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public interface OpenTelemetryLogConfig {
/**
* Determine whether to enable the OpenTelemetry logging handler
*/
@WithDefault("false")
@WithDefault("true")
boolean enabled();
}

0 comments on commit c52c74f

Please sign in to comment.