From 52848c9b47e32f208aed9b56086f0ec2aaf95989 Mon Sep 17 00:00:00 2001 From: Andre Onuki Date: Fri, 14 Oct 2022 10:19:47 -0400 Subject: [PATCH 1/3] NR-57169 - Enable CLM on default --- .../config/CodeLevelMetricsConfigImpl.java | 2 +- .../src/main/resources/newrelic.yml | 2 +- .../CodeLevelMetricsConfigImplTest.java | 25 ++++++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/CodeLevelMetricsConfigImpl.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/CodeLevelMetricsConfigImpl.java index 511b7a0134..9d7849ad63 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/CodeLevelMetricsConfigImpl.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/CodeLevelMetricsConfigImpl.java @@ -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; diff --git a/newrelic-agent/src/main/resources/newrelic.yml b/newrelic-agent/src/main/resources/newrelic.yml index f110819d30..96160f1643 100644 --- a/newrelic-agent/src/main/resources/newrelic.yml +++ b/newrelic-agent/src/main/resources/newrelic.yml @@ -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 diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/config/CodeLevelMetricsConfigImplTest.java b/newrelic-agent/src/test/java/com/newrelic/agent/config/CodeLevelMetricsConfigImplTest.java index ce5178be75..25fc66e0c7 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/config/CodeLevelMetricsConfigImplTest.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/config/CodeLevelMetricsConfigImplTest.java @@ -26,14 +26,21 @@ 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()); } @@ -41,8 +48,8 @@ public void enabled() { @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), @@ -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()); } } \ No newline at end of file From 3204df26b0fc0f17069ff0fa00744f363693b1b5 Mon Sep 17 00:00:00 2001 From: Andre Onuki Date: Fri, 14 Oct 2022 17:12:21 -0400 Subject: [PATCH 2/3] Disabling CLM for existing tests. --- .../test/resources/com/newrelic/agent/config/span_events.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/newrelic-agent/src/test/resources/com/newrelic/agent/config/span_events.yml b/newrelic-agent/src/test/resources/com/newrelic/agent/config/span_events.yml index 821548d90b..0cef67980a 100644 --- a/newrelic-agent/src/test/resources/com/newrelic/agent/config/span_events.yml +++ b/newrelic-agent/src/test/resources/com/newrelic/agent/config/span_events.yml @@ -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/.* From 3941b4f64cbb8198829cab88213fdddd53e5de0c Mon Sep 17 00:00:00 2001 From: Andre Onuki Date: Fri, 14 Oct 2022 18:10:54 -0400 Subject: [PATCH 3/3] Fixing TransactionTest --- .../test/java/com/newrelic/agent/metrics/JsonTraceSegment.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/metrics/JsonTraceSegment.java b/newrelic-agent/src/test/java/com/newrelic/agent/metrics/JsonTraceSegment.java index 52bd83abb3..62a013edd1 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/metrics/JsonTraceSegment.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/metrics/JsonTraceSegment.java @@ -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; }