Skip to content

Commit 6b994d0

Browse files
committed
Revert "Enable Redis Logging (dotnet#597)"
This reverts commit d9e8e95. With dotnet@a3ed2b5, the proxyless container changes were reverted. Redis logging relied on these changes for a decent user experience. Reverting back to preview1 behavior until the proxyless container changes can be made again.
1 parent 64fbf75 commit 6b994d0

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/Components/Aspire.StackExchange.Redis/AspireRedisExtensions.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
global using System.Net.Security; // needed to work around https://github.com/dotnet/runtime/issues/94065
55

6+
using System.Text;
67
using Aspire;
78
using Aspire.StackExchange.Redis;
89
using Microsoft.Extensions.Configuration;
@@ -88,12 +89,12 @@ private static void AddRedis(IHostApplicationBuilder builder, string configurati
8889
if (serviceKey is null)
8990
{
9091
builder.Services.AddSingleton<IConnectionMultiplexer>(
91-
sp => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName)));
92+
sp => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName), CreateLogger(sp)));
9293
}
9394
else
9495
{
9596
builder.Services.AddKeyedSingleton<IConnectionMultiplexer>(serviceKey,
96-
(sp, key) => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName)));
97+
(sp, key) => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName), CreateLogger(sp)));
9798
}
9899

99100
if (settings.Tracing)
@@ -119,6 +120,11 @@ private static void AddRedis(IHostApplicationBuilder builder, string configurati
119120
connectionMultiplexerFactory: sp => serviceKey is null ? sp.GetRequiredService<IConnectionMultiplexer>() : sp.GetRequiredKeyedService<IConnectionMultiplexer>(serviceKey),
120121
healthCheckName));
121122
}
123+
124+
static TextWriter? CreateLogger(IServiceProvider serviceProvider)
125+
=> serviceProvider.GetService<ILoggerFactory>() is { } loggerFactory
126+
? new LoggingTextWriter(loggerFactory.CreateLogger("Aspire.StackExchange.Redis"))
127+
: null;
122128
}
123129

124130
private static ConfigurationOptions GetConfigurationOptions(IServiceProvider serviceProvider, string connectionName, string configurationSectionName, string? optionsName)
@@ -132,9 +138,6 @@ private static ConfigurationOptions GetConfigurationOptions(IServiceProvider ser
132138
throw new InvalidOperationException($"No endpoints specified. Ensure a valid connection string was provided in 'ConnectionStrings:{connectionName}' or for the '{configurationSectionName}:ConnectionString' configuration key.");
133139
}
134140

135-
// ensure the LoggerFactory is initialized if someone hasn't already set it.
136-
configurationOptions.LoggerFactory ??= serviceProvider.GetService<ILoggerFactory>();
137-
138141
return configurationOptions;
139142
}
140143

@@ -146,6 +149,13 @@ private static ConfigurationOptions BindToConfiguration(ConfigurationOptions opt
146149
return options;
147150
}
148151

152+
private sealed class LoggingTextWriter(ILogger logger) : TextWriter
153+
{
154+
public override Encoding Encoding => Encoding.UTF8;
155+
156+
public override void Write(string? value) => logger.LogTrace(value);
157+
}
158+
149159
/// <summary>
150160
/// ConfigurationOptionsFactory parses a ConfigurationOptions options object from Configuration.
151161
/// </summary>

src/Components/Aspire.StackExchange.Redis/ConfigurationSchema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"definitions": {
33
"logLevel": {
44
"properties": {
5-
"StackExchange.Redis": {
5+
"Aspire.StackExchange.Redis": {
66
"$ref": "#/definitions/logLevelThreshold"
77
}
88
}

src/Components/Telemetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Aspire.RabbitMQ.Client:
233233

234234
Aspire.StackExchange.Redis:
235235
- Log categories:
236-
- "StackExchange.Redis"
236+
- "Aspire.StackExchange.Redis" (this name is defined by our component, we can change it)
237237
- Activity source names:
238238
- "OpenTelemetry.Instrumentation.StackExchangeRedis"
239239
- Metric names:

tests/Aspire.StackExchange.Redis.Tests/ConformanceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ConformanceTests : ConformanceTests<IConnectionMultiplexer, StackEx
2020

2121
protected override bool SupportsKeyedRegistrations => true;
2222

23-
protected override string[] RequiredLogCategories => new string[] { "StackExchange.Redis" };
23+
protected override string[] RequiredLogCategories => new string[] { "Aspire.StackExchange.Redis" };
2424

2525
// https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/e4cb523a4a3592e1a1adf30f3596025bfd8978e3/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs#L34
2626
protected override string ActivitySourceName => "OpenTelemetry.Instrumentation.StackExchangeRedis";

0 commit comments

Comments
 (0)