diff --git a/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/FeatureManagement/FeatureFlagTracing.cs b/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/FeatureManagement/FeatureFlagTracing.cs index bc582cc1..7fc359df 100644 --- a/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/FeatureManagement/FeatureFlagTracing.cs +++ b/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/FeatureManagement/FeatureFlagTracing.cs @@ -14,11 +14,6 @@ namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.FeatureManage /// internal class FeatureFlagTracing { - private const string CustomFilter = "CSTM"; - private const string PercentageFilter = "PRCNT"; - private const string TimeWindowFilter = "TIME"; - private const string TargetingFilter = "TRGT"; - // Built-in Feature Filter Names private readonly List PercentageFilterNames = new List { "Percentage", "Microsoft.Percentage", "PercentageFilter", "Microsoft.PercentageFilter" }; private readonly List TimeWindowFilterNames = new List { "TimeWindow", "Microsoft.TimeWindow", "TimeWindowFilter", "Microsoft.TimeWindowFilter" }; @@ -82,5 +77,87 @@ public void NotifyMaxVariants(int currentFlagTotalVariants) MaxVariants = currentFlagTotalVariants; } } + + /// + /// Returns a formatted string containing code names, indicating which feature filters are used by the application. + /// + /// Formatted string like: "CSTM+PRCNT+TIME+TRGT", "PRCNT+TRGT", etc. If no filters are used, empty string will be returned. + public string CreateFiltersString() + { + var sb = new StringBuilder(); + + if (UsesCustomFilter) + { + sb.Append(RequestTracingConstants.CustomFilter); + } + + if (UsesPercentageFilter) + { + if (sb.Length > 0) + { + sb.Append(RequestTracingConstants.Delimiter); + } + + sb.Append(RequestTracingConstants.PercentageFilter); + } + + if (UsesTimeWindowFilter) + { + if (sb.Length > 0) + { + sb.Append(RequestTracingConstants.Delimiter); + } + + sb.Append(RequestTracingConstants.TimeWindowFilter); + } + + if (UsesTargetingFilter) + { + if (sb.Length > 0) + { + sb.Append(RequestTracingConstants.Delimiter); + } + + sb.Append(RequestTracingConstants.TargetingFilter); + } + + return sb.ToString(); + } + + /// + /// Returns a formatted string containing code names, indicating which tracing features are used by feature flags. + /// + /// Formatted string like: "Seed+ConfigRef+Telemnetry". If no tracing features are used, empty string will be returned. + public string CreateFeaturesString() + { + var sb = new StringBuilder(); + + if (UsesSeed) + { + sb.Append(RequestTracingConstants.FeatureFlagUsesSeedTag); + } + + if (UsesVariantConfigurationReference) + { + if (sb.Length > 0) + { + sb.Append(RequestTracingConstants.Delimiter); + } + + sb.Append(RequestTracingConstants.FeatureFlagUsesVariantConfigurationReferenceTag); + } + + if (UsesTelemetry) + { + if (sb.Length > 0) + { + sb.Append(RequestTracingConstants.Delimiter); + } + + sb.Append(RequestTracingConstants.FeatureFlagUsesTelemetryTag); + } + + return sb.ToString(); + } } } diff --git a/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/RequestTracingOptions.cs b/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/RequestTracingOptions.cs index 26028fab..f9bf4dfa 100644 --- a/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/RequestTracingOptions.cs +++ b/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/RequestTracingOptions.cs @@ -71,5 +71,31 @@ public bool UsesAnyTracingFeature() { return IsLoadBalancingEnabled || IsSignalRUsed; } + + /// + /// Returns a formatted string containing code names, indicating which tracing features are used by the application. + /// + /// Formatted string like: "LB+SignalR". If no tracing features are used, empty string will be returned. + public string CreateFeaturesString() + { + var sb = new StringBuilder(); + + if (IsLoadBalancingEnabled) + { + sb.Append(RequestTracingConstants.LoadBalancingEnabledTag); + } + + if (IsSignalRUsed) + { + if (sb.Length > 0) + { + sb.Append(RequestTracingConstants.Delimiter); + } + + sb.Append(RequestTracingConstants.SignalRUsedTag); + } + + return sb.ToString(); + } } } diff --git a/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/TracingUtils.cs b/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/TracingUtils.cs index dbc52292..30e86457 100644 --- a/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/TracingUtils.cs +++ b/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/TracingUtils.cs @@ -159,7 +159,7 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re if (requestTracingOptions.FeatureFlagTracing.UsesAnyFeatureFilter()) { - correlationContextKeyValues.Add(new KeyValuePair(RequestTracingConstants.FeatureFlagFilterTypeKey, CreateFiltersString(requestTracingOptions.FeatureFlagTracing))); + correlationContextKeyValues.Add(new KeyValuePair(RequestTracingConstants.FeatureFlagFilterTypeKey, requestTracingOptions.FeatureFlagTracing.CreateFiltersString())); } if (requestTracingOptions.FeatureFlagTracing.MaxVariants > 0) @@ -169,7 +169,7 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re if (requestTracingOptions.FeatureFlagTracing.UsesAnyTracingFeature()) { - correlationContextKeyValues.Add(new KeyValuePair(RequestTracingConstants.FeatureFlagFeaturesKey, CreateFeatureFlagFeaturesString(requestTracingOptions.FeatureFlagTracing))); + correlationContextKeyValues.Add(new KeyValuePair(RequestTracingConstants.FeatureFlagFeaturesKey, requestTracingOptions.FeatureFlagTracing.CreateFeaturesString())); } if (requestTracingOptions.FeatureManagementVersion != null) @@ -184,7 +184,7 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re if (requestTracingOptions.UsesAnyTracingFeature()) { - correlationContextKeyValues.Add(new KeyValuePair(RequestTracingConstants.FeaturesKey, CreateFeaturesString(requestTracingOptions))); + correlationContextKeyValues.Add(new KeyValuePair(RequestTracingConstants.FeaturesKey, requestTracingOptions.CreateFeaturesString())); } if (requestTracingOptions.IsKeyVaultConfigured) @@ -226,113 +226,5 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re return sb.ToString(); } - - /// - /// Returns a formatted string containing code names, indicating which tracing features are used by the application. - /// - /// Formatted string like: "LB+SignalR". If no tracing features are used, empty string will be returned. - private static string CreateFeaturesString(RequestTracingOptions requestTracingOptions) - { - var sb = new StringBuilder(); - - if (requestTracingOptions.IsLoadBalancingEnabled) - { - sb.Append(RequestTracingConstants.LoadBalancingEnabledTag); - } - - if (requestTracingOptions.IsSignalRUsed) - { - if (sb.Length > 0) - { - sb.Append(RequestTracingConstants.Delimiter); - } - - sb.Append(RequestTracingConstants.SignalRUsedTag); - } - - return sb.ToString(); - } - - /// - /// Returns a formatted string containing code names, indicating which tracing features are used by feature flags. - /// - /// Formatted string like: "Seed+ConfigRef+Telemnetry". If no tracing features are used, empty string will be returned. - private static string CreateFeatureFlagFeaturesString(FeatureFlagTracing featureFlagTracing) - { - var sb = new StringBuilder(); - - if (featureFlagTracing.UsesSeed) - { - sb.Append(RequestTracingConstants.FeatureFlagUsesSeedTag); - } - - if (featureFlagTracing.UsesVariantConfigurationReference) - { - if (sb.Length > 0) - { - sb.Append(RequestTracingConstants.Delimiter); - } - - sb.Append(RequestTracingConstants.FeatureFlagUsesVariantConfigurationReferenceTag); - } - - if (featureFlagTracing.UsesTelemetry) - { - if (sb.Length > 0) - { - sb.Append(RequestTracingConstants.Delimiter); - } - - sb.Append(RequestTracingConstants.FeatureFlagUsesTelemetryTag); - } - - return sb.ToString(); - } - - /// - /// Returns a formatted string containing code names, indicating which feature filters are used by the application. - /// - /// Formatted string like: "CSTM+PRCNT+TIME+TRGT". If no filters are used, empty string will be returned. - private static string CreateFiltersString(FeatureFlagTracing featureFlagTracing) - { - var sb = new StringBuilder(); - - if (featureFlagTracing.UsesCustomFilter) - { - sb.Append(RequestTracingConstants.CustomFilter); - } - - if (featureFlagTracing.UsesPercentageFilter) - { - if (sb.Length > 0) - { - sb.Append(RequestTracingConstants.Delimiter); - } - - sb.Append(RequestTracingConstants.PercentageFilter); - } - - if (featureFlagTracing.UsesTimeWindowFilter) - { - if (sb.Length > 0) - { - sb.Append(RequestTracingConstants.Delimiter); - } - - sb.Append(RequestTracingConstants.TimeWindowFilter); - } - - if (featureFlagTracing.UsesTargetingFilter) - { - if (sb.Length > 0) - { - sb.Append(RequestTracingConstants.Delimiter); - } - - sb.Append(RequestTracingConstants.TargetingFilter); - } - - return sb.ToString(); - } } }