Skip to content

Commit

Permalink
NR-57169 - Enable CLM by default (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
meiao authored Oct 17, 2022
1 parent ced4864 commit 9e78796
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class CodeLevelMetricsConfigImpl extends BaseConfig implements CodeLevelMetricsConfig {
public static final String SYSTEM_PROPERTY_ROOT = "newrelic.config." + AgentConfigImpl.CODE_LEVEL_METRICS + ".";

public static final boolean DEFAULT_ENABLED = false;
public static final boolean DEFAULT_ENABLED = true;
public static final String ENABLED = "enabled";

private final boolean clmEnabled;
Expand Down
2 changes: 1 addition & 1 deletion newrelic-agent/src/main/resources/newrelic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ common: &default_settings

# When true the agent will capture namespace and function information
# on spans to enable code level metrics in CodeStream.
enabled: false
enabled: true

# Proxy settings for connecting to the New Relic server:
# If a proxy is used, the host setting is required. Other settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,30 @@ public void setup() {
}

@Test
public void disabledByDefault() {
public void enabledByDefault() {
CodeLevelMetricsConfigImpl config = new CodeLevelMetricsConfigImpl(localProps);
assertFalse(config.isEnabled());
assertTrue(config.isEnabled());
}

@Test
public void enabled() {
localProps.put("code_level_metrics.enabled", true);
localProps.put("enabled", true);
CodeLevelMetricsConfigImpl config = new CodeLevelMetricsConfigImpl(localProps);
assertTrue(config.isEnabled());
}

@Test
public void disabled() {
localProps.put("enabled", false);
CodeLevelMetricsConfigImpl config = new CodeLevelMetricsConfigImpl(localProps);
assertFalse(config.isEnabled());
}

@Test
public void canConfigureViaSystemProperty() {
Properties properties = new Properties();
//default CLM is false
properties.put("newrelic.config.code_level_metrics.enabled", "true");
//default CLM is true
properties.put("newrelic.config.code_level_metrics.enabled", "false");

SystemPropertyFactory.setSystemPropertyProvider(new SystemPropertyProvider(
new SaveSystemPropertyProviderRule.TestSystemProps(properties),
Expand All @@ -51,22 +58,22 @@ public void canConfigureViaSystemProperty() {
));

CodeLevelMetricsConfigImpl config = new CodeLevelMetricsConfigImpl(Collections.emptyMap());
assertTrue(config.isEnabled());
assertFalse(config.isEnabled());

}

@Test
public void canConfigureViaEnvironmentVariables() {

//default CLM is false
//default CLM is true
SystemPropertyFactory.setSystemPropertyProvider(new SystemPropertyProvider(
new SaveSystemPropertyProviderRule.TestSystemProps(), //use default configs except for CLM
new SaveSystemPropertyProviderRule.TestEnvironmentFacade(Collections.singletonMap("NEW_RELIC_CODE_LEVEL_METRICS_ENABLED", "true"))
new SaveSystemPropertyProviderRule.TestEnvironmentFacade(Collections.singletonMap("NEW_RELIC_CODE_LEVEL_METRICS_ENABLED", "false"))
));

CodeLevelMetricsConfigImpl config = new CodeLevelMetricsConfigImpl(Collections.emptyMap());

assertTrue(config.isEnabled());
assertFalse(config.isEnabled());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public static JsonTraceSegment createTraceSegment(JSONArray segmentArray, String
}
seg.className = (String) segmentArray.get(5);
seg.methodName = (String) segmentArray.get(6);

seg.requestParams.put("code.namespace", seg.className);
seg.requestParams.put("code.function", seg.methodName);
return seg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ common: &default_settings
- !exception_handler [ "test/newrelic/test/agent/ExceptionHandlerTest$ExceptionHandler", "handleSpecialException", "(Ljava/lang/RuntimeException;Ljava/lang/String;)V" ]
- test/newrelic/test/agent/ExceptionHandlerTest$ExceptionHandler.handleException2(Ljava/lang/String;Ljava/lang/Throwable;)V

code_level_metrics:
enabled: false
class_transformer:
includes: com/newrelic/.*Test, java.util.TreeMap, javax/activation/MimeType, com/newrelic/.*Object, java/awt/Shape, java/awt/geom/Line2D*, java/awt/geom/Path2D*, com/sun/grizzly/tcp/Request, com/sun/grizzly/util/http/Cookies, org/objectweb/asm/ClassWriter
excludes: org/junit/.*
Expand Down

0 comments on commit 9e78796

Please sign in to comment.