From ae97c0f2ef3219f3a0e2713c814164e6e4eee0c5 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Mon, 10 Jul 2023 13:19:59 -0500 Subject: [PATCH] chore: Merge log level filtering poc branch to new feature branch (#1763) * Prototype for log level deny list * Clean up naming * Re-added the license header --------- Co-authored-by: Jacob Affinito --- src/Agent/NewRelic/Agent/Core/Agent.cs | 6 ++++++ .../NewRelic/Agent/Core/Config/Configuration.cs | 15 +++++++++++++++ .../NewRelic/Agent/Core/Config/Configuration.xsd | 9 +++++++++ .../Core/Configuration/DefaultConfiguration.cs | 10 ++++++++++ .../Core/Configuration/ReportedConfiguration.cs | 3 +++ .../Configuration/IConfiguration.cs | 1 + .../DataTransport/ExhaustiveTestConfiguration.cs | 2 ++ 7 files changed, 46 insertions(+) diff --git a/src/Agent/NewRelic/Agent/Core/Agent.cs b/src/Agent/NewRelic/Agent/Core/Agent.cs index 160ae0835..96316ad84 100644 --- a/src/Agent/NewRelic/Agent/Core/Agent.cs +++ b/src/Agent/NewRelic/Agent/Core/Agent.cs @@ -420,6 +420,12 @@ public void RecordLogMessage(string frameworkName, object logEvent, Func /// configurationApplicationLoggingForwarding class constructor /// @@ -5085,6 +5087,19 @@ public int maxSamplesStored } } + [System.Xml.Serialization.XmlAttributeAttribute()] + public string logLevelDenylist + { + get + { + return this.logLevelDenylistField; + } + set + { + this.logLevelDenylistField = value; + } + } + #region Clone method /// /// Create a clone of this configurationApplicationLoggingForwarding object diff --git a/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd b/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd index 5e1a5b6f7..d7fbb1530 100644 --- a/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd +++ b/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd @@ -1655,6 +1655,15 @@ + + + + + A comma-separated, case-insensitive, list of log levels that should be ignored and not sent up to New Relic. + + + + diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs index 0dd1c410f..83fe525e2 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs @@ -1990,6 +1990,16 @@ public virtual bool LogDecoratorEnabled } } + public virtual IEnumerable LogLevelDenylist + { + get + { + return EnvironmentOverrides(_localConfiguration.applicationLogging.forwarding.logLevelDenylist, + "NEW_RELIC_APPLICATION_LOGGING_FORWARDING_LOG_LEVEL_DENYLIST") + .Split(new[] { StringSeparators.CommaChar, ' ' }, StringSplitOptions.RemoveEmptyEntries); + } + } + #endregion public virtual bool AppDomainCachingDisabled diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs index 0699761b3..3751412b0 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs @@ -599,6 +599,9 @@ public ReportedConfiguration(IConfiguration configuration) [JsonProperty("application_logging.local_decorating.enabled")] public bool LogDecoratorEnabled => _configuration.LogDecoratorEnabled; + [JsonProperty("application_logging.log_level_denylist")] + public IEnumerable LogLevelDenylist => _configuration.LogLevelDenylist; + [JsonProperty("agent.app_domain_caching_disabled")] public bool AppDomainCachingDisabled => _configuration.AppDomainCachingDisabled; diff --git a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs index 5a8a6dd67..ffdd5ee87 100644 --- a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs @@ -190,6 +190,7 @@ public interface IConfiguration int LogEventsMaxSamplesStored { get; } TimeSpan LogEventsHarvestCycle { get; } bool LogDecoratorEnabled { get; } + IEnumerable LogLevelDenylist { get; } bool ContextDataEnabled { get; } IEnumerable ContextDataInclude { get; } IEnumerable ContextDataExclude { get; } diff --git a/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs b/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs index 480dbe063..8a709aac3 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs @@ -415,6 +415,8 @@ public class ExhaustiveTestConfiguration : IConfiguration public bool LogDecoratorEnabled => true; + public IEnumerable LogLevelDenylist => new List { "testlevel" } ; + public bool AppDomainCachingDisabled => true; public bool ForceNewTransactionOnNewThread => true;