Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Warn about unsupported async return types #2565

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading