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

Add an env var for disabling auto collected logging #3622

Merged
merged 3 commits into from
Apr 3, 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 @@ -116,6 +116,9 @@ public class ConfigurationBuilder {
private static final String APPLICATIONINSIGHTS_STATSBEAT_DISABLED =
"APPLICATIONINSIGHTS_STATSBEAT_DISABLED";

private static final String APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED =
"APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED";

// cannot use logger before loading configuration, so need to store warning messages locally until
// logger is initialized
private static final ConfigurationLogger configurationLogger = new ConfigurationLogger();
Expand Down Expand Up @@ -486,9 +489,23 @@ private static void overlayAadEnvVars(Configuration config) {
}

private static void loadLogCaptureEnvVar(Configuration config) {
String loggingEnvVar = getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL);
if (loggingEnvVar != null) {
config.instrumentation.logging.level = loggingEnvVar;
String loggingEnabled = getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED);
heyams marked this conversation as resolved.
Show resolved Hide resolved
if (loggingEnabled != null) {
configurationLogger.debug(
"applying environment variable: {}={}",
APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED,
loggingEnabled);
config.instrumentation.logging.enabled = Boolean.parseBoolean(loggingEnabled);
}
if (config.instrumentation.logging.enabled) {
String loggingLevel = getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL);
if (loggingLevel != null) {
configurationLogger.debug(
"applying environment variable: {}={}",
APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL,
loggingLevel);
config.instrumentation.logging.level = loggingLevel;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ void shouldOverrideLogCaptureThreshold() throws IOException {
assertThat(configuration.instrumentation.logging.level).isEqualTo("TRACE");
}

@Test
void shouldOverrideLoggingEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED", "false");

Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));

assertThat(configuration.instrumentation.logging.enabled).isEqualTo(false);
}

@Test
void shouldOverrideJmxMetrics() throws IOException {
String jmxMetricsJson =
Expand Down