diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md index 9aa2cc6049..0de7a0b741 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md @@ -18,6 +18,11 @@ `TracerProvider` has been created. ([#1193](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1193)) +* When using named options the name will now be applied to the background thread + created for each instrumented connection in the format + `OpenTelemetry.Redis{OPTIONS_NAME_HERE}`. + ([#1205](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1205)) + ## 1.0.0-rc9.8 Released 2023-Feb-27 diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs index 4d09b762d1..f1a4a9e528 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisConnectionInstrumentation.cs @@ -53,8 +53,12 @@ internal sealed class StackExchangeRedisConnectionInstrumentation : IDisposable /// Initializes a new instance of the class. /// /// to instrument. + /// Optional name for the connection. /// Configuration options for redis instrumentation. - public StackExchangeRedisConnectionInstrumentation(IConnectionMultiplexer connection, StackExchangeRedisInstrumentationOptions options) + public StackExchangeRedisConnectionInstrumentation( + IConnectionMultiplexer connection, + string? name, + StackExchangeRedisInstrumentationOptions options) { Guard.ThrowIfNull(connection); @@ -62,7 +66,7 @@ public StackExchangeRedisConnectionInstrumentation(IConnectionMultiplexer connec this.drainThread = new Thread(this.DrainEntries) { - Name = "OpenTelemetry.Redis", + Name = string.IsNullOrWhiteSpace(name) ? "OpenTelemetry.Redis" : $"OpenTelemetry.Redis{{{name}}}", IsBackground = true, }; this.drainThread.Start(); diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentation.cs b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentation.cs index cee5940681..cd8fdbb3f1 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentation.cs +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/StackExchangeRedisInstrumentation.cs @@ -58,7 +58,7 @@ public IDisposable AddConnection(string name, IConnectionMultiplexer connection) lock (this.InstrumentedConnections) { - var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, options); + var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, name, options); this.InstrumentedConnections.Add(instrumentation); diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index d0be5f00d2..c3b40c7050 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -158,7 +158,7 @@ public async void ProfilerSessionUsesTheSameDefault() var connection = ConnectionMultiplexer.Connect(connectionOptions); - using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, new StackExchangeRedisInstrumentationOptions()); + using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, name: null, new StackExchangeRedisInstrumentationOptions()); var profilerFactory = instrumentation.GetProfilerSessionsFactory(); var first = profilerFactory(); var second = profilerFactory(); @@ -236,7 +236,7 @@ public void CheckCacheIsFlushedProperly() var connection = ConnectionMultiplexer.Connect(connectionOptions); - using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, new StackExchangeRedisInstrumentationOptions()); + using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, name: null, new StackExchangeRedisInstrumentationOptions()); var profilerFactory = instrumentation.GetProfilerSessionsFactory(); // start a root level activity @@ -276,7 +276,7 @@ public async Task ProfilerSessionsHandleMultipleSpans() var connection = ConnectionMultiplexer.Connect(connectionOptions); - using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, new StackExchangeRedisInstrumentationOptions()); + using var instrumentation = new StackExchangeRedisConnectionInstrumentation(connection, name: null, new StackExchangeRedisInstrumentationOptions()); var profilerFactory = instrumentation.GetProfilerSessionsFactory(); // start a root level activity