From dad1cc0330a5e652be7e11652a7904af50268e02 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 31 Oct 2023 17:40:47 -0500 Subject: [PATCH 1/2] Fix up Redis trimming annotations #1415 had an issue in it due to how the DynamicDependency attribute is written. 1. Referring to a nested type with `+` isn't correct in DynamicDependency attributes. You need to just use a normal `.`. The current code is producing a warning when using the .NET 8.0 SDK to publish for AOT. "warning IL2036: OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation.RedisProfilerEntryToActivityConverter.<.cctor>g__GetCommandAndKey|5_3(PropertyFetcher`1,Object,String&): Unresolved type 'StackExchange.Redis.RedisDatabase+ScriptEvalMessage' in 'DynamicDependencyAttribute'." This wasn't caught in our CI because we use the .NET 7.0 SDK to publish, which doesn't catch this bug. 2. The "CommandAndKey" property isn't on the nested ScriptEvalMessage type, but instead a virtual on the base Message class. The fix here is to use the base Message class in the DynamicDependency. I've verified this works with a .NET 8.0 SDK. --- .../Implementation/RedisProfilerEntryToActivityConverter.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs index 3c34c5bf98..aef136e3e7 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs @@ -29,12 +29,10 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation; internal static class RedisProfilerEntryToActivityConverter { - private const string ScriptEvalMessageTypeName = "StackExchange.Redis.RedisDatabase+ScriptEvalMessage"; - private static readonly Lazy> MessageDataGetter = new(() => { Type profiledCommandType = Type.GetType("StackExchange.Redis.Profiling.ProfiledCommand, StackExchange.Redis", throwOnError: true)!; - Type scriptMessageType = Type.GetType(ScriptEvalMessageTypeName + ", StackExchange.Redis", throwOnError: true)!; + Type scriptMessageType = Type.GetType("StackExchange.Redis.RedisDatabase+ScriptEvalMessage, StackExchange.Redis", throwOnError: true)!; var messageDelegate = CreateFieldGetter(profiledCommandType, "Message", BindingFlags.NonPublic | BindingFlags.Instance); var scriptDelegate = CreateFieldGetter(scriptMessageType, "script", BindingFlags.NonPublic | BindingFlags.Instance); @@ -72,7 +70,7 @@ internal static class RedisProfilerEntryToActivityConverter return (null, script); #if NET6_0_OR_GREATER - [DynamicDependency("CommandAndKey", ScriptEvalMessageTypeName, "StackExchange.Redis")] + [DynamicDependency("CommandAndKey", "StackExchange.Redis.Message", "StackExchange.Redis")] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The CommandAndKey property is preserved by the above DynamicDependency")] #endif static bool GetCommandAndKey( From a2e13ca04d5b4d5ad824c80b3a15ff48ed33487a Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 31 Oct 2023 17:44:47 -0500 Subject: [PATCH 2/2] Add changelog --- .../CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md index c45bf08a64..bbab8572f4 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Fix an issue in the trimming annotations to refer to the correct Type + ([#1420](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1420)) + ## 1.0.0-rc9.11 Released 2023-Oct-31