From 45f2dc2f22628c4eb6993278522834678636ba9d Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 31 Oct 2023 13:19:27 -0500 Subject: [PATCH 1/2] Update Redis dependencies - the client library and otel packages have new versions, update to the latest - SE.Redis have ILogger support now, update to use it --- .../AspireRedisExtensions.cs | 12 +++++------- .../ConfigurationSchema.json | 2 +- src/Components/Telemetry.md | 2 +- .../ConformanceTests.cs | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs b/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs index 40f04227794..51cc615ffba 100644 --- a/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs +++ b/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs @@ -89,12 +89,12 @@ private static void AddRedis(IHostApplicationBuilder builder, string configurati if (serviceKey is null) { builder.Services.AddSingleton( - sp => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName), CreateLogger(sp))); + sp => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName))); } else { builder.Services.AddKeyedSingleton(serviceKey, - (sp, key) => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName), CreateLogger(sp))); + (sp, key) => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName))); } if (settings.Tracing) @@ -120,11 +120,6 @@ private static void AddRedis(IHostApplicationBuilder builder, string configurati connectionMultiplexerFactory: sp => serviceKey is null ? sp.GetRequiredService() : sp.GetRequiredKeyedService(serviceKey), healthCheckName)); } - - static TextWriter? CreateLogger(IServiceProvider serviceProvider) - => serviceProvider.GetService() is { } loggerFactory - ? new LoggingTextWriter(loggerFactory.CreateLogger("Aspire.StackExchange.Redis")) - : null; } private static ConfigurationOptions GetConfigurationOptions(IServiceProvider serviceProvider, string connectionName, string configurationSectionName, string? optionsName) @@ -138,6 +133,9 @@ private static ConfigurationOptions GetConfigurationOptions(IServiceProvider ser throw new InvalidOperationException($"No endpoints specified. Ensure a valid connection string was provided in 'ConnectionStrings:{connectionName}' or for the '{configurationSectionName}:ConnectionString' configuration key."); } + // ensure the LoggerFactory is initialized if someone hasn't already set it. + configurationOptions.LoggerFactory ??= serviceProvider.GetService(); + return configurationOptions; } diff --git a/src/Components/Aspire.StackExchange.Redis/ConfigurationSchema.json b/src/Components/Aspire.StackExchange.Redis/ConfigurationSchema.json index 4308accbaf5..1adb6a12c95 100644 --- a/src/Components/Aspire.StackExchange.Redis/ConfigurationSchema.json +++ b/src/Components/Aspire.StackExchange.Redis/ConfigurationSchema.json @@ -2,7 +2,7 @@ "definitions": { "logLevel": { "properties": { - "Aspire.StackExchange.Redis": { + "StackExchange.Redis": { "$ref": "#/definitions/logLevelThreshold" } } diff --git a/src/Components/Telemetry.md b/src/Components/Telemetry.md index d55e0b7543d..8ea002b65f4 100644 --- a/src/Components/Telemetry.md +++ b/src/Components/Telemetry.md @@ -220,7 +220,7 @@ Aspire.RabbitMQ.Client: Aspire.StackExchange.Redis: - Log categories: - - "Aspire.StackExchange.Redis" (this name is defined by our component, we can change it) + - "StackExchange.Redis" - Activity source names: - "OpenTelemetry.Instrumentation.StackExchangeRedis" - Metric names: diff --git a/tests/Aspire.StackExchange.Redis.Tests/ConformanceTests.cs b/tests/Aspire.StackExchange.Redis.Tests/ConformanceTests.cs index 2474ac75aca..29d7581ed8f 100644 --- a/tests/Aspire.StackExchange.Redis.Tests/ConformanceTests.cs +++ b/tests/Aspire.StackExchange.Redis.Tests/ConformanceTests.cs @@ -20,7 +20,7 @@ public class ConformanceTests : ConformanceTests true; - protected override string[] RequiredLogCategories => new string[] { "Aspire.StackExchange.Redis" }; + protected override string[] RequiredLogCategories => new string[] { "StackExchange.Redis" }; // https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/e4cb523a4a3592e1a1adf30f3596025bfd8978e3/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs#L34 protected override string ActivitySourceName => "OpenTelemetry.Instrumentation.StackExchangeRedis"; From d97bfeb45c642a743b3383fb350f8424e1fd661d Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 1 Dec 2023 17:51:38 -0600 Subject: [PATCH 2/2] Remove unused class. --- .../Aspire.StackExchange.Redis/AspireRedisExtensions.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs b/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs index 51cc615ffba..d9b392b74ea 100644 --- a/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs +++ b/src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs @@ -3,7 +3,6 @@ global using System.Net.Security; // needed to work around https://github.com/dotnet/runtime/issues/94065 -using System.Text; using Aspire; using Aspire.StackExchange.Redis; using Microsoft.Extensions.Configuration; @@ -147,13 +146,6 @@ private static ConfigurationOptions BindToConfiguration(ConfigurationOptions opt return options; } - private sealed class LoggingTextWriter(ILogger logger) : TextWriter - { - public override Encoding Encoding => Encoding.UTF8; - - public override void Write(string? value) => logger.LogTrace(value); - } - /// /// ConfigurationOptionsFactory parses a ConfigurationOptions options object from Configuration. ///