From b1a0803b22b923ae27a0764c1c5efa5db5ed4713 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 24 May 2023 10:24:22 -0700 Subject: [PATCH 1/3] Append options name to the background thread used to drain Redis profiling sessions. --- .../CHANGELOG.md | 5 +++++ .../StackExchangeRedisConnectionInstrumentation.cs | 8 ++++++-- .../StackExchangeRedisInstrumentation.cs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md index 9aa2cc6049..340c4845c6 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}`. + ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/XXXX)) + ## 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); From 9b270c7a79865a4bc41d8b61be6c00b0f9cf3bf7 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 24 May 2023 10:32:24 -0700 Subject: [PATCH 2/3] Test fixes. --- .../StackExchangeRedisCallsInstrumentationTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 64fb0b8c4acba518449ff9647f3e11ff5f4b3960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 25 May 2023 06:43:28 +0200 Subject: [PATCH 3/3] Fix link in changelog Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> --- .../CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md index 340c4845c6..0de7a0b741 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md @@ -21,7 +21,7 @@ * 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}`. - ([#XXXX](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/XXXX)) + ([#1205](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1205)) ## 1.0.0-rc9.8