Skip to content

Commit

Permalink
Merge pull request #817 from newrelic/enable-app-logging-by-default
Browse files Browse the repository at this point in the history
Enable application_logging by default
  • Loading branch information
jasonjkeller authored Apr 19, 2022
2 parents cb52695 + 57443e5 commit 1bcada3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* application_logging:
* enabled: true
* forwarding:
* enabled: false
* enabled: true
* max_samples_stored: 10000
* metrics:
* enabled: true
Expand Down Expand Up @@ -69,6 +69,7 @@ static ApplicationLoggingConfigImpl createApplicationLoggingConfig(Map<String, O
return new ApplicationLoggingConfigImpl(settings, highSecurity);
}

@Override
public boolean isEnabled() {
return applicationLoggingEnabled;
}
Expand All @@ -88,6 +89,7 @@ public boolean isForwardingEnabled() {
return applicationLoggingEnabled && applicationLoggingForwardingConfig.getEnabled();
}

@Override
public int getMaxSamplesStored() {
return applicationLoggingForwardingConfig.getMaxSamplesStored();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ApplicationLoggingForwardingConfig extends BaseConfig {
public static final String ENABLED = "enabled";
public static final String MAX_SAMPLES_STORED = "max_samples_stored";

public static final boolean DEFAULT_ENABLED = false;
public static final boolean DEFAULT_ENABLED = true;
public static final int DEFAULT_MAX_SAMPLES_STORED = 10000;

private final boolean enabled;
Expand Down
6 changes: 3 additions & 3 deletions newrelic-agent/src/main/resources/newrelic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ common: &default_settings

# The agent will automatically forward application logs to New Relic in
# a format that includes agent metadata for linking them to traces and errors.
#forwarding:
forwarding:

# When true, application logs will be forwarded to New Relic. The default is false.
#enabled: false
# When true, application logs will be forwarded to New Relic. The default is true.
enabled: true

# Application log events are collected up to the configured amount. Afterwards,
# events are sampled to maintain an even distribution across the harvest cycle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,10 @@ public void getApplicationLoggingConfig() {
AgentConfig config = AgentConfigImpl.createAgentConfig(localMap);

assertEquals(ApplicationLoggingConfigImpl.DEFAULT_ENABLED, config.getApplicationLoggingConfig().isEnabled());
assertTrue(config.getApplicationLoggingConfig().isForwardingEnabled());
assertFalse(config.getApplicationLoggingConfig().isForwardingEnabled());
assertEquals(NOT_DEFAULT_MAX_SAMPLES_STORED, config.getApplicationLoggingConfig().getMaxSamplesStored());
assertFalse(config.getApplicationLoggingConfig().isMetricsEnabled());
assertTrue(config.getApplicationLoggingConfig().isLocalDecoratingEnabled());

}

@Test
Expand All @@ -1268,16 +1267,14 @@ public void getApplicationLoggingConfigDefaults() {
AgentConfig config = AgentConfigImpl.createAgentConfig(localMap);

assertTrue(config.getApplicationLoggingConfig().isEnabled());
assertFalse(config.getApplicationLoggingConfig().isForwardingEnabled());
assertTrue(config.getApplicationLoggingConfig().isForwardingEnabled());
assertEquals(ApplicationLoggingForwardingConfig.DEFAULT_MAX_SAMPLES_STORED, config.getApplicationLoggingConfig().getMaxSamplesStored());
assertTrue(config.getApplicationLoggingConfig().isMetricsEnabled());
assertFalse(config.getApplicationLoggingConfig().isLocalDecoratingEnabled());

}

@Test
public void getApplicationLoggingConfigSystemProperty() {

String key = ApplicationLoggingConfigImpl.SYSTEM_PROPERTY_ROOT + ApplicationLoggingConfigImpl.ENABLED;
String val = String.valueOf(!ApplicationLoggingConfigImpl.DEFAULT_ENABLED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class ApplicationLoggingForwardingConfigTest {
private Map<String, Object> localProps;
private static final int TEST_MAX_SAMPLES_STORED = 5000;

@Rule
public SaveSystemPropertyProviderRule saveSystemPropertyProviderRule = new SaveSystemPropertyProviderRule();
private Map<String, Object> localProps;

@Before
public void setup() {
Expand All @@ -30,8 +29,7 @@ public void setup() {
public void defaultForwardingConfig() {
ApplicationLoggingForwardingConfig config = new ApplicationLoggingForwardingConfig(localProps, ApplicationLoggingConfigImpl.SYSTEM_PROPERTY_ROOT,
false);
assertFalse(config.getEnabled());

assertTrue(config.getEnabled());
}

@Test
Expand All @@ -46,7 +44,8 @@ public void testMaxSamplesStoredDefaultValueIfValueTooLargeForInteger() {
Map<String, Object> maxSamplesStoreTooLarge = new HashMap<>(localProps);
maxSamplesStoreTooLarge.put(ApplicationLoggingForwardingConfig.MAX_SAMPLES_STORED, new BigInteger("9999999999999999999999"));

ApplicationLoggingForwardingConfig config = new ApplicationLoggingForwardingConfig(maxSamplesStoreTooLarge, ApplicationLoggingConfigImpl.SYSTEM_PROPERTY_ROOT,
ApplicationLoggingForwardingConfig config = new ApplicationLoggingForwardingConfig(maxSamplesStoreTooLarge,
ApplicationLoggingConfigImpl.SYSTEM_PROPERTY_ROOT,
false);
assertEquals(ApplicationLoggingForwardingConfig.DEFAULT_MAX_SAMPLES_STORED, config.getMaxSamplesStored());
}
Expand All @@ -61,7 +60,6 @@ public void testMaxSamplesStoredNotDefaultValue() {

@Test
public void usesEnvVarForNestedConfig() {

SystemPropertyFactory.setSystemPropertyProvider(new SystemPropertyProvider(
new SaveSystemPropertyProviderRule.TestSystemProps(),
new SaveSystemPropertyProviderRule.TestEnvironmentFacade(
Expand All @@ -71,13 +69,11 @@ public void usesEnvVarForNestedConfig() {
ApplicationLoggingForwardingConfig config = new ApplicationLoggingForwardingConfig(Collections.emptyMap(),
ApplicationLoggingConfigImpl.SYSTEM_PROPERTY_ROOT, false);
assertEquals(TEST_MAX_SAMPLES_STORED, config.getMaxSamplesStored());

}

@Test
public void usesSysPropForNestedConfig() {
Properties properties = new Properties();

properties.put("newrelic.config.application_logging.forwarding.max_samples_stored", "" + TEST_MAX_SAMPLES_STORED);
SystemPropertyFactory.setSystemPropertyProvider(new SystemPropertyProvider(
new SaveSystemPropertyProviderRule.TestSystemProps(properties),
Expand All @@ -87,7 +83,6 @@ public void usesSysPropForNestedConfig() {
ApplicationLoggingForwardingConfig config = new ApplicationLoggingForwardingConfig(Collections.emptyMap(),
ApplicationLoggingConfigImpl.SYSTEM_PROPERTY_ROOT, false);
assertEquals(TEST_MAX_SAMPLES_STORED, config.getMaxSamplesStored());

}

}

0 comments on commit 1bcada3

Please sign in to comment.