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

Fix OFF logging threshold #2592

Merged
merged 1 commit into from
Oct 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

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

(suggestion) This method might be moved in AgentLogExporter and called around line 84. So all the log logic would be in the place where we need it. A boolean exportLog(LogData log, String configuredLogThreshold) method might then be added and contains all the log level logic for the export. The configuration object would then represent the log level as a string an not an int.

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 looks a bit more challenging, as we are also using this method for fail-fast validation of the configuration:

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