Skip to content

Commit

Permalink
chore: Merge log level filtering poc branch to new feature branch (#1763
Browse files Browse the repository at this point in the history
)

* Prototype for log level deny list

* Clean up naming

* Re-added the license header

---------

Co-authored-by: Jacob Affinito <[email protected]>
  • Loading branch information
tippmar-nr and jaffinito authored Jul 10, 2023
1 parent 32f966d commit ae97c0f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ public void RecordLogMessage(string frameworkName, object logEvent, Func<object,
normalizedLevel = string.IsNullOrWhiteSpace(level) ? "UNKNOWN" : level.ToUpper();
}

// we want to ignore case so that we don't have to normalize the deny-list values
if (_configurationService.Configuration.LogLevelDenylist.Contains(normalizedLevel, StringComparer.OrdinalIgnoreCase))
{
return;
}

if (_configurationService.Configuration.LogMetricsCollectorEnabled)
{
_agentHealthReporter.IncrementLogLinesCount(normalizedLevel);
Expand Down
15 changes: 15 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5035,6 +5035,8 @@ public partial class configurationApplicationLoggingForwarding

private int maxSamplesStoredField;

private string logLevelDenylistField;

/// <summary>
/// configurationApplicationLoggingForwarding class constructor
/// </summary>
Expand Down Expand Up @@ -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
/// <summary>
/// Create a clone of this configurationApplicationLoggingForwarding object
Expand Down
9 changes: 9 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,15 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>

<xs:attribute name="logLevelDenylist" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>
A comma-separated, case-insensitive, list of log levels that should be ignored and not sent up to New Relic.
</xs:documentation>
</xs:annotation>
</xs:attribute>

</xs:complexType>
</xs:element>
<xs:element name="localDecorating" minOccurs="0" maxOccurs="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,16 @@ public virtual bool LogDecoratorEnabled
}
}

public virtual IEnumerable<string> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> LogLevelDenylist => _configuration.LogLevelDenylist;

[JsonProperty("agent.app_domain_caching_disabled")]
public bool AppDomainCachingDisabled => _configuration.AppDomainCachingDisabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public interface IConfiguration
int LogEventsMaxSamplesStored { get; }
TimeSpan LogEventsHarvestCycle { get; }
bool LogDecoratorEnabled { get; }
IEnumerable<string> LogLevelDenylist { get; }
bool ContextDataEnabled { get; }
IEnumerable<string> ContextDataInclude { get; }
IEnumerable<string> ContextDataExclude { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ public class ExhaustiveTestConfiguration : IConfiguration

public bool LogDecoratorEnabled => true;

public IEnumerable<string> LogLevelDenylist => new List<string> { "testlevel" } ;

public bool AppDomainCachingDisabled => true;

public bool ForceNewTransactionOnNewThread => true;
Expand Down

0 comments on commit ae97c0f

Please sign in to comment.