From 71b54f1cdfdd2104b6246ecc30e70be320bfb6c3 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Mon, 5 Feb 2024 12:15:46 +0100 Subject: [PATCH] Ensure exposes default constants are readonly. (#2278) * Ensure exposes default constants are readonly. Technically a breaking change but since noone should be modifying these directly we treat this as a BUG not a breaking change * IReadOnlyList is less breaking than IReadOnlyCollection --- src/Elastic.Apm/Config/ConfigConsts.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Elastic.Apm/Config/ConfigConsts.cs b/src/Elastic.Apm/Config/ConfigConsts.cs index 9ce6ea4b0..36671af72 100644 --- a/src/Elastic.Apm/Config/ConfigConsts.cs +++ b/src/Elastic.Apm/Config/ConfigConsts.cs @@ -69,17 +69,17 @@ public static class DefaultValues "Giraffe." }.AsReadOnly(); - public static List DisableMetrics = new List(); + public static readonly IReadOnlyList DisableMetrics = new List().AsReadOnly(); - public static List IgnoreMessageQueues = new List(); + public static readonly IReadOnlyList IgnoreMessageQueues = new List().AsReadOnly(); - public static List SanitizeFieldNames; + public static readonly IReadOnlyList SanitizeFieldNames; - public static List TransactionIgnoreUrls; + public static readonly IReadOnlyList TransactionIgnoreUrls; static DefaultValues() { - SanitizeFieldNames = new List(); + var sanitizeFieldNames = new List(); foreach (var item in new List { "password", @@ -95,9 +95,10 @@ static DefaultValues() "set-cookie", "*principal*" }) - SanitizeFieldNames.Add(WildcardMatcher.ValueOf(item)); + sanitizeFieldNames.Add(WildcardMatcher.ValueOf(item)); + SanitizeFieldNames = sanitizeFieldNames.AsReadOnly(); - TransactionIgnoreUrls = new List(); + var transactionIgnoreUrls = new List(); foreach (var item in new List { @@ -115,7 +116,8 @@ static DefaultValues() "*.woff", "*.woff2" }) - TransactionIgnoreUrls.Add(WildcardMatcher.ValueOf(item)); + transactionIgnoreUrls.Add(WildcardMatcher.ValueOf(item)); + TransactionIgnoreUrls = transactionIgnoreUrls.AsReadOnly(); } public static Uri ServerUri => new Uri($"http://127.0.0.1:{ApmServerPort}"); @@ -138,11 +140,11 @@ public static class SupportedValues public const string CloudProviderGcp = GcpCloudMetadataProvider.Name; public const string CloudProviderNone = "none"; - public static readonly List CaptureBodySupportedValues = new() { CaptureBodyOff, CaptureBodyAll, CaptureBodyErrors, CaptureBodyTransactions }; + public static readonly IReadOnlyCollection CaptureBodySupportedValues = new List { CaptureBodyOff, CaptureBodyAll, CaptureBodyErrors, CaptureBodyTransactions }.AsReadOnly(); - public static readonly List TraceContinuationStrategySupportedValues = new() { Continue, Restart, RestartExternal }; + public static readonly IReadOnlyCollection TraceContinuationStrategySupportedValues = new List { Continue, Restart, RestartExternal }.AsReadOnly(); - public static readonly HashSet CloudProviders = new HashSet(StringComparer.OrdinalIgnoreCase) + public static readonly IReadOnlyCollection CloudProviders = new HashSet(StringComparer.OrdinalIgnoreCase) { CloudProviderAuto, CloudProviderAws,