Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,12 +88,12 @@ private static void AddRedis(IHostApplicationBuilder builder, string configurati
if (serviceKey is null)
{
builder.Services.AddSingleton<IConnectionMultiplexer>(
sp => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName), CreateLogger(sp)));
sp => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName)));
}
else
{
builder.Services.AddKeyedSingleton<IConnectionMultiplexer>(serviceKey,
(sp, key) => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName), CreateLogger(sp)));
(sp, key) => ConnectionMultiplexer.Connect(GetConfigurationOptions(sp, connectionName, configurationSectionName, optionsName)));
}

if (settings.Tracing)
Expand All @@ -120,11 +119,6 @@ private static void AddRedis(IHostApplicationBuilder builder, string configurati
connectionMultiplexerFactory: sp => serviceKey is null ? sp.GetRequiredService<IConnectionMultiplexer>() : sp.GetRequiredKeyedService<IConnectionMultiplexer>(serviceKey),
healthCheckName));
}

static TextWriter? CreateLogger(IServiceProvider serviceProvider)
=> serviceProvider.GetService<ILoggerFactory>() is { } loggerFactory
? new LoggingTextWriter(loggerFactory.CreateLogger("Aspire.StackExchange.Redis"))
: null;
}

private static ConfigurationOptions GetConfigurationOptions(IServiceProvider serviceProvider, string connectionName, string configurationSectionName, string? optionsName)
Expand All @@ -138,6 +132,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<ILoggerFactory>();

return configurationOptions;
}

Expand All @@ -149,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);
}

/// <summary>
/// ConfigurationOptionsFactory parses a ConfigurationOptions options object from Configuration.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"definitions": {
"logLevel": {
"properties": {
"Aspire.StackExchange.Redis": {
"StackExchange.Redis": {
"$ref": "#/definitions/logLevelThreshold"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.StackExchange.Redis.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ConformanceTests : ConformanceTests<IConnectionMultiplexer, StackEx

protected override bool SupportsKeyedRegistrations => 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";
Expand Down