From 5c341d5d4b3aa4516586c341ceb49aea35abdd6c Mon Sep 17 00:00:00 2001 From: martintmk <103487740+martintmk@users.noreply.github.com> Date: Fri, 16 Jun 2023 17:28:51 +0200 Subject: [PATCH] Rename `TelemetryResilienceStrategyOptions` to `TelemetryOptions` (#1318) --- bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs | 2 +- .../DependencyInjection/PollyServiceCollectionExtensions.cs | 4 ++-- src/Polly.Extensions/Telemetry/EnrichmentContext.cs | 2 +- .../Telemetry/ResilienceTelemetryDiagnosticSource.cs | 2 +- ...emetryResilienceStrategyOptions.cs => TelemetryOptions.cs} | 2 +- .../Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs | 4 ++-- .../PollyServiceCollectionExtensionTests.cs | 2 +- .../Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs | 4 ++-- ...lienceStrategyOptionsTests.cs => TelemetryOptionsTests.cs} | 4 ++-- .../TelemetryResilienceStrategyBuilderExtensionsTests.cs | 4 ++-- 10 files changed, 15 insertions(+), 15 deletions(-) rename src/Polly.Extensions/Telemetry/{TelemetryResilienceStrategyOptions.cs => TelemetryOptions.cs} (96%) rename test/Polly.Extensions.Tests/Telemetry/{TelemetryResilienceStrategyOptionsTests.cs => TelemetryOptionsTests.cs} (86%) diff --git a/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs b/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs index fd57299cb6a..23143f6e3fe 100644 --- a/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs +++ b/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs @@ -34,7 +34,7 @@ private ResilienceStrategy Build(ResilienceStrategyBuilder builder) if (Telemetry) { - TelemetryResilienceStrategyOptions options = new() { LoggerFactory = NullLoggerFactory.Instance }; + TelemetryOptions options = new() { LoggerFactory = NullLoggerFactory.Instance }; if (Enrichment) { diff --git a/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs b/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs index 02d4d911c7f..0f4c577357b 100644 --- a/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs +++ b/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs @@ -209,7 +209,7 @@ private static IServiceCollection AddResilienceStrategyRegistry(this IServ private static void AddResilienceStrategyBuilder(this IServiceCollection services) { services - .AddOptions() + .AddOptions() .Configure((options, serviceProvider) => { options.LoggerFactory = serviceProvider.GetService() ?? NullLoggerFactory.Instance; @@ -219,7 +219,7 @@ private static void AddResilienceStrategyBuilder(this IServiceCollection service { var builder = new ResilienceStrategyBuilder(); builder.Properties.Set(PollyDependencyInjectionKeys.ServiceProvider, serviceProvider); - builder.EnableTelemetry(serviceProvider.GetRequiredService>().Value); + builder.EnableTelemetry(serviceProvider.GetRequiredService>().Value); return builder; }); } diff --git a/src/Polly.Extensions/Telemetry/EnrichmentContext.cs b/src/Polly.Extensions/Telemetry/EnrichmentContext.cs index 1c52947c752..51b54c2a111 100644 --- a/src/Polly.Extensions/Telemetry/EnrichmentContext.cs +++ b/src/Polly.Extensions/Telemetry/EnrichmentContext.cs @@ -1,7 +1,7 @@ namespace Polly.Extensions.Telemetry; /// -/// Enrichment context used when reporting resilience telemetry. This context is passed to the registered enrichers in . +/// Enrichment context used when reporting resilience telemetry. This context is passed to the registered enrichers in . /// public sealed partial class EnrichmentContext { diff --git a/src/Polly.Extensions/Telemetry/ResilienceTelemetryDiagnosticSource.cs b/src/Polly.Extensions/Telemetry/ResilienceTelemetryDiagnosticSource.cs index 801e831c529..1d555c8adf8 100644 --- a/src/Polly.Extensions/Telemetry/ResilienceTelemetryDiagnosticSource.cs +++ b/src/Polly.Extensions/Telemetry/ResilienceTelemetryDiagnosticSource.cs @@ -12,7 +12,7 @@ internal class ResilienceTelemetryDiagnosticSource : DiagnosticSource private readonly ILogger _logger; private readonly List> _enrichers; - public ResilienceTelemetryDiagnosticSource(TelemetryResilienceStrategyOptions options) + public ResilienceTelemetryDiagnosticSource(TelemetryOptions options) { _enrichers = options.Enrichers.ToList(); _logger = options.LoggerFactory.CreateLogger(TelemetryUtil.PollyDiagnosticSource); diff --git a/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyOptions.cs b/src/Polly.Extensions/Telemetry/TelemetryOptions.cs similarity index 96% rename from src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyOptions.cs rename to src/Polly.Extensions/Telemetry/TelemetryOptions.cs index 5a64149a173..e6554cf519d 100644 --- a/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyOptions.cs +++ b/src/Polly.Extensions/Telemetry/TelemetryOptions.cs @@ -9,7 +9,7 @@ namespace Polly.Extensions.Telemetry; /// /// The options that are used to configure the telemetry that is produced by the resilience strategies. /// -public class TelemetryResilienceStrategyOptions +public class TelemetryOptions { /// /// Gets or sets the logger factory. diff --git a/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs b/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs index 5fc987fb38f..58a1a9c9660 100644 --- a/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs @@ -28,7 +28,7 @@ public static TBuilder EnableTelemetry(this TBuilder builder, ILoggerF Guard.NotNull(builder); Guard.NotNull(loggerFactory); - return builder.EnableTelemetry(new TelemetryResilienceStrategyOptions { LoggerFactory = loggerFactory }); + return builder.EnableTelemetry(new TelemetryOptions { LoggerFactory = loggerFactory }); } /// @@ -43,7 +43,7 @@ public static TBuilder EnableTelemetry(this TBuilder builder, ILoggerF /// Additionally, the telemetry strategy that logs and meters the executions is added to the beginning of the strategy pipeline. /// /// Thrown when or is . - public static TBuilder EnableTelemetry(this TBuilder builder, TelemetryResilienceStrategyOptions options) + public static TBuilder EnableTelemetry(this TBuilder builder, TelemetryOptions options) where TBuilder : ResilienceStrategyBuilderBase { Guard.NotNull(builder); diff --git a/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs b/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs index 5f7b3454e01..e21ccb3fe25 100644 --- a/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs +++ b/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs @@ -147,7 +147,7 @@ public void AddResilienceStrategy_EnsureTelemetryEnabled(bool hasLogging) var diagSource = telemetry!.GetType().GetProperty("DiagnosticSource", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(telemetry); diagSource.Should().BeOfType(); - var factory = _services.BuildServiceProvider().GetRequiredService>().Value.LoggerFactory; + var factory = _services.BuildServiceProvider().GetRequiredService>().Value.LoggerFactory; if (hasLogging) { diff --git a/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs b/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs index a672f50079e..727160aaebb 100644 --- a/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs @@ -30,7 +30,7 @@ public void Meter_Ok() { ResilienceTelemetryDiagnosticSource.Meter.Name.Should().Be("Polly"); ResilienceTelemetryDiagnosticSource.Meter.Version.Should().Be("1.0"); - new ResilienceTelemetryDiagnosticSource(new TelemetryResilienceStrategyOptions()) + new ResilienceTelemetryDiagnosticSource(new TelemetryOptions()) .Counter.Description.Should().Be("Tracks the number of resilience events that occurred in resilience strategies."); } @@ -207,7 +207,7 @@ public void WriteEvent_MeteringWithoutStrategyKey_Ok() private ResilienceTelemetryDiagnosticSource Create(Action>>? configureEnrichers = null) { - var options = new TelemetryResilienceStrategyOptions + var options = new TelemetryOptions { LoggerFactory = _loggerFactory }; diff --git a/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyOptionsTests.cs b/test/Polly.Extensions.Tests/Telemetry/TelemetryOptionsTests.cs similarity index 86% rename from test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyOptionsTests.cs rename to test/Polly.Extensions.Tests/Telemetry/TelemetryOptionsTests.cs index f7ce5713d59..6f21c4f047a 100644 --- a/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyOptionsTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/TelemetryOptionsTests.cs @@ -5,12 +5,12 @@ namespace Polly.Extensions.Tests.Telemetry; -public class TelemetryResilienceStrategyOptionsTests +public class TelemetryOptionsTests { [Fact] public void Ctor_EnsureDefaults() { - var options = new TelemetryResilienceStrategyOptions(); + var options = new TelemetryOptions(); options.Enrichers.Should().BeEmpty(); options.LoggerFactory.Should().Be(NullLoggerFactory.Instance); diff --git a/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs index 85906a3550c..600da828fe6 100644 --- a/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs @@ -53,7 +53,7 @@ public void EnableTelemetry_EnsureLogging(bool generic) public void EnableTelemetry_InvalidOptions_Throws() { _builder - .Invoking(b => b.EnableTelemetry(new TelemetryResilienceStrategyOptions + .Invoking(b => b.EnableTelemetry(new TelemetryOptions { LoggerFactory = null!, })).Should() @@ -66,7 +66,7 @@ The LoggerFactory field is required. """); _genericBuilder - .Invoking(b => b.EnableTelemetry(new TelemetryResilienceStrategyOptions + .Invoking(b => b.EnableTelemetry(new TelemetryOptions { LoggerFactory = null!, })).Should()