Skip to content

fix: Error when decorating duplicate generic method - Tracing #572

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

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public object Handle(
};

var wrappers = triggers.OfType<UniversalWrapperAttribute>().ToArray();
var handler = GetMethodHandler(method, returnType, wrappers);
// Target.Method is more precise for cases when decorating generic methods
var handler = GetMethodHandler(target.Method, returnType, wrappers);
return handler(target, args, eventArgs);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Globalization;
using System.Threading.Tasks;

namespace AWS.Lambda.Powertools.Tracing.Tests.Handlers;

public class FunctionHandlerForGeneric
{
[Tracing(CaptureMode = TracingCaptureMode.ResponseAndError)]
public async Task<string> Handle(string input)
{
GenericMethod<int>(1);
GenericMethod<double>(2);

GenericMethod<int>(1);

GenericMethod<int>();
GenericMethod<double>();

GenericMethod2<int>(1);
GenericMethod2<double>(2);

GenericMethod<int>();
GenericMethod<double>();

await Task.Delay(1);

return input.ToUpper(CultureInfo.InvariantCulture);
}

[Tracing]
private T GenericMethod<T>(T x)
{
return default;
}

[Tracing]
private T GenericMethod<T>()
{
return default;
}

[Tracing]
private void GenericMethod2<T>(T x)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AWS.Lambda.Powertools.Tracing.Tests.Handlers;

public sealed class ExceptionFunctionHandlerTests
public sealed class HandlerTests
{
[Fact]
public async Task Stack_Trace_Included_When_Decorator_Present()
Expand All @@ -20,4 +20,17 @@ public async Task Stack_Trace_Included_When_Decorator_Present()
Assert.StartsWith("at AWS.Lambda.Powertools.Tracing.Tests.Handlers.ExceptionFunctionHandler.ThisThrows()", tracedException.StackTrace?.TrimStart());

}

[Fact]
public async Task When_Decorator_Present_In_Generic_Method_Should_Not_Throw_When_Type_Changes()
{
// Arrange
var handler = new FunctionHandlerForGeneric();

// Act
await handler.Handle("whatever");

// Assert

}
}