Skip to content

Commit

Permalink
Ensure exposes default constants are readonly. (#2278)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Mpdreamz authored Feb 5, 2024
1 parent 11de017 commit 71b54f1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Elastic.Apm/Config/ConfigConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ public static class DefaultValues
"Giraffe."
}.AsReadOnly();

public static List<WildcardMatcher> DisableMetrics = new List<WildcardMatcher>();
public static readonly IReadOnlyList<WildcardMatcher> DisableMetrics = new List<WildcardMatcher>().AsReadOnly();

public static List<WildcardMatcher> IgnoreMessageQueues = new List<WildcardMatcher>();
public static readonly IReadOnlyList<WildcardMatcher> IgnoreMessageQueues = new List<WildcardMatcher>().AsReadOnly();

public static List<WildcardMatcher> SanitizeFieldNames;
public static readonly IReadOnlyList<WildcardMatcher> SanitizeFieldNames;

public static List<WildcardMatcher> TransactionIgnoreUrls;
public static readonly IReadOnlyList<WildcardMatcher> TransactionIgnoreUrls;

static DefaultValues()
{
SanitizeFieldNames = new List<WildcardMatcher>();
var sanitizeFieldNames = new List<WildcardMatcher>();
foreach (var item in new List<string>
{
"password",
Expand All @@ -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<WildcardMatcher>();
var transactionIgnoreUrls = new List<WildcardMatcher>();

foreach (var item in new List<string>
{
Expand All @@ -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}");
Expand All @@ -138,11 +140,11 @@ public static class SupportedValues
public const string CloudProviderGcp = GcpCloudMetadataProvider.Name;
public const string CloudProviderNone = "none";

public static readonly List<string> CaptureBodySupportedValues = new() { CaptureBodyOff, CaptureBodyAll, CaptureBodyErrors, CaptureBodyTransactions };
public static readonly IReadOnlyCollection<string> CaptureBodySupportedValues = new List<string> { CaptureBodyOff, CaptureBodyAll, CaptureBodyErrors, CaptureBodyTransactions }.AsReadOnly();

public static readonly List<string> TraceContinuationStrategySupportedValues = new() { Continue, Restart, RestartExternal };
public static readonly IReadOnlyCollection<string> TraceContinuationStrategySupportedValues = new List<string> { Continue, Restart, RestartExternal }.AsReadOnly();

public static readonly HashSet<string> CloudProviders = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
public static readonly IReadOnlyCollection<string> CloudProviders = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
CloudProviderAuto,
CloudProviderAws,
Expand Down

0 comments on commit 71b54f1

Please sign in to comment.