From afa022bacfa48f80dcb89a619c4622e0e6aa82e8 Mon Sep 17 00:00:00 2001 From: chynesNR Date: Tue, 18 Jun 2024 13:33:10 -0700 Subject: [PATCH] chore: Warn about unsupported async return types --- .../Agent/Core/Wrapper/WrapperService.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Agent/NewRelic/Agent/Core/Wrapper/WrapperService.cs b/src/Agent/NewRelic/Agent/Core/Wrapper/WrapperService.cs index f263789c0..0bff391d5 100644 --- a/src/Agent/NewRelic/Agent/Core/Wrapper/WrapperService.cs +++ b/src/Agent/NewRelic/Agent/Core/Wrapper/WrapperService.cs @@ -10,6 +10,8 @@ using NewRelic.Agent.Core.Utilities; using NewRelic.Agent.Extensions.Logging; using NewRelic.Agent.Api; +using System.Reflection; +using System.Threading.Tasks; namespace NewRelic.Agent.Core.Wrapper { @@ -88,6 +90,23 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(Type type, string methodNa return null; } + if (isAsync) + { + try + { + var returnType = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).ReturnType; + if ((returnType != typeof(Task)) && + (!returnType.IsGenericType || (returnType.GetGenericTypeDefinition() != typeof(Task<>)))) + { + Log.Warn("Instrumenting async methods that return a type other than Task or Task<> is not supported and may result in inconsistent data. '{0}' has a return type of '{1}'.", methodName, returnType?.Name); + } + } + catch + { + // Since this is just for logging purposes it doesn't matter if it fails + } + } + _functionIdToWrapper[functionId] = new InstrumentedMethodInfoWrapper(instrumentedMethodInfo, trackedWrapper); GenerateLibraryVersionSupportabilityMetric(instrumentedMethodInfo); }