Skip to content

Commit

Permalink
chore: Warn about unsupported async return types
Browse files Browse the repository at this point in the history
  • Loading branch information
chynesNR committed Jun 18, 2024
1 parent bb46aca commit afa022b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Wrapper/WrapperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit afa022b

Please sign in to comment.