Skip to content

Commit

Permalink
Fix OFF logging threshold (#2592)
Browse files Browse the repository at this point in the history
Resolves #2590
  • Loading branch information
trask committed Oct 18, 2022
1 parent 5706863 commit b95f877
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static boolean isEmpty(@Nullable String str) {
}

public void validate() {
instrumentation.logging.getSeverity();
instrumentation.logging.getSeverityThreshold();
preview.validate();
}

Expand Down Expand Up @@ -220,32 +220,33 @@ public static class DatabaseMaskingConfiguration {
public static class LoggingInstrumentation {
public String level = "INFO";

public Severity getSeverity() {
return getSeverity(level);
public int getSeverityThreshold() {
return getSeverityThreshold(level);
}

public static Severity getSeverity(String level) {
public static int getSeverityThreshold(String level) {
switch (level.toUpperCase()) {
case "OFF":
return Severity.UNDEFINED_SEVERITY_NUMBER;
return Integer.MAX_VALUE;
case "FATAL":
return Severity.FATAL.getSeverityNumber();
case "ERROR":
case "SEVERE":
return Severity.ERROR;
return Severity.ERROR.getSeverityNumber();
case "WARN":
case "WARNING":
return Severity.WARN;
return Severity.WARN.getSeverityNumber();
case "INFO":
return Severity.INFO;
return Severity.INFO.getSeverityNumber();
case "CONFIG":
case "DEBUG":
case "FINE":
case "FINER":
return Severity.DEBUG;
return Severity.DEBUG.getSeverityNumber();
case "TRACE":
case "FINEST":
case "ALL":
return Severity.TRACE;
return Severity.TRACE.getSeverityNumber();
default:
throw new FriendlyException(
"Invalid logging instrumentation level: " + level, "Please provide a valid level.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.logs.export.LogExporter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Collection;
Expand All @@ -38,21 +37,21 @@ public class AgentLogExporter implements LogExporter {
new OperationLogger(AgentLogExporter.class, "Exporting log");

// TODO (trask) could implement this in a filtering LogExporter instead
private volatile Severity threshold;
private volatile int severityThreshold;

private final SamplingOverrides logSamplingOverrides;
private final SamplingOverrides exceptionSamplingOverrides;
private final LogDataMapper mapper;
private final Consumer<TelemetryItem> telemetryItemConsumer;

public AgentLogExporter(
Severity threshold,
int severityThreshold,
List<SamplingOverride> logSamplingOverrides,
List<SamplingOverride> exceptionSamplingOverrides,
LogDataMapper mapper,
@Nullable QuickPulse quickPulse,
BatchItemProcessor batchItemProcessor) {
this.threshold = threshold;
this.severityThreshold = severityThreshold;
this.logSamplingOverrides = new SamplingOverrides(logSamplingOverrides);
this.exceptionSamplingOverrides = new SamplingOverrides(exceptionSamplingOverrides);
this.mapper = mapper;
Expand All @@ -68,8 +67,8 @@ public AgentLogExporter(
};
}

public void setThreshold(Severity threshold) {
this.threshold = threshold;
public void setSeverityThreshold(int severityThreshold) {
this.severityThreshold = severityThreshold;
}

@Override
Expand All @@ -82,9 +81,8 @@ public CompletableResultCode export(Collection<LogData> logs) {
for (LogData log : logs) {
logger.debug("exporting log: {}", log);
try {
int severity = log.getSeverity().getSeverityNumber();
int threshold = this.threshold.getSeverityNumber();
if (severity < threshold) {
int severityNumber = log.getSeverity().getSeverityNumber();
if (severityNumber < severityThreshold) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ private void initialize() {
setWebsiteSiteName(websiteSiteName);
setSelfDiagnosticsLevel(selfDiagnosticsLevel);
if (instrumentationLoggingLevel != null) {
agentLogExporter.setThreshold(
Configuration.LoggingInstrumentation.getSeverity(instrumentationLoggingLevel));
agentLogExporter.setSeverityThreshold(
Configuration.LoggingInstrumentation.getSeverityThreshold(instrumentationLoggingLevel));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ private static LogExporter createLogExporter(

agentLogExporter =
new AgentLogExporter(
configuration.instrumentation.logging.getSeverity(),
configuration.instrumentation.logging.getSeverityThreshold(),
logSamplingOverrides,
exceptionSamplingOverrides,
mapper,
Expand Down

0 comments on commit b95f877

Please sign in to comment.