From b3486676c6d3a2ffa3c2f432e50599bbbb4ad1ca Mon Sep 17 00:00:00 2001 From: Henrique Graca <999396+hjgraca@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:09:10 +0000 Subject: [PATCH 1/4] Update index to add supported runtimes Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com> --- docs/index.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 515bd07dc..b78a36c7a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,7 +7,10 @@ description: Powertools for AWS Lambda (.NET) # Powertools for AWS Lambda (.NET) -Powertools for AWS Lambda (.NET) (which from here will be referred as Powertools) is a suite of utilities for [AWS Lambda](https://aws.amazon.com/lambda/) functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more. Please note, **Powertools for AWS Lambda (.NET) is optimized for .NET 6+**. +Powertools for AWS Lambda (.NET) (which from here will be referred as Powertools) is a suite of utilities for [AWS Lambda](https://aws.amazon.com/lambda/) functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more. + +!!! info + **Supports .NET 6 and .NET 8 runtimes** ???+ tip Powertools is also available for [Python](https://docs.powertools.aws.dev/lambda/python/){target="_blank"}, [Java](https://docs.powertools.aws.dev/lambda/java/){target="_blank"}, and [TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/){target="_blank"}. From cf31888f731bac0f7ebb9f8f4dbd2f838e1b0fc9 Mon Sep 17 00:00:00 2001 From: Henrique Graca <999396+hjgraca@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:15:14 +0000 Subject: [PATCH 2/4] Update README.md Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41b3cb349..59ffc737b 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Powertools for AWS Lambda (.NET) provides three core utilities: ### Installation -The Powertools for AWS Lambda (.NET) utilities (.NET 6) are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*) or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available. +The Powertools for AWS Lambda (.NET) utilities (.NET 6 and .NET 8) are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*) or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available. * [AWS.Lambda.Powertools.Logging](https://www.nuget.org/packages?q=AWS.Lambda.Powertools.Logging): @@ -61,7 +61,7 @@ The Powertools for AWS Lambda (.NET) utilities (.NET 6) are available as NuGet p ## Examples -We have provided examples focused specifically on each of the utilities. Each solution comes with an AWS Serverless Application Model (AWS SAM) templates to run your functions as a Zip package using the AWS Lambda .NET 6 managed runtime; or as a container package using the AWS base images for .NET. +We have provided examples focused specifically on each of the utilities. Each solution comes with an AWS Serverless Application Model (AWS SAM) templates to run your functions as a Zip package using the AWS Lambda .NET 6 or .NET 8 managed runtime; or as a container package using the AWS base images for .NET. * **[Logging example](examples/Logging/)** * **[Metrics example](examples/Metrics/)** From b2c6988d925a3ddcddb695543dc81a5227886ad7 Mon Sep 17 00:00:00 2001 From: Henrique Graca <999396+hjgraca@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:17:56 +0000 Subject: [PATCH 3/4] Update badges Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59ffc737b..f87c2d114 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ ![aws provider](https://img.shields.io/badge/provider-AWS-orange?logo=amazon-aws&color=ff9900) [![Build](https://github.com/aws-powertools/powertools-lambda-dotnet/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/aws-powertools/powertools-lambda-dotnet/actions/workflows/build.yml) [![codecov.io](https://codecov.io/github/aws-powertools/powertools-lambda-dotnet/branch/develop/graphs/badge.svg)](https://app.codecov.io/gh/aws-powertools/powertools-lambda-dotnet) -[![dotnet support](https://img.shields.io/static/v1?label=dotnet&message=%20NET6.0&color=blue?style=flat-square&logo=dotnet)](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) +[![dotnet support](https://img.shields.io/static/v1?label=dotnet&message=%20NET6.0|NET8.0&color=blue?style=flat-square&logo=dotnet)](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) [![NuGet Downloads](https://img.shields.io/nuget/dt/AWS.Lambda.Powertools.Logging.svg)](https://www.nuget.org/packages?q=AWS.Lambda.Powertools) -[![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET)](https://discord.gg/B8zZKbbyET) +[![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET?style=flat-square)](https://discord.gg/B8zZKbbyET) Powertools for AWS Lambda (.NET) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda-dotnet/#features). From bdb02b7bafedbf3ef7fe9deae67b286932c31bca Mon Sep 17 00:00:00 2001 From: Henrique Graca <999396+hjgraca@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:09:07 +0000 Subject: [PATCH 4/4] GetMethodHandler: replace method parameter with target.Method parameter which is more precise and avoids collision when decorating generic methods with tracing attribute. Add tests. --- .../Aspects/UniversalWrapperAspect.cs | 3 +- .../Handlers/FunctionHandlerForGeneric.cs | 46 +++++++++++++++++++ ...unctionHandlerTests.cs => HandlerTests.cs} | 15 +++++- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/FunctionHandlerForGeneric.cs rename libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/{ExceptionFunctionHandlerTests.cs => HandlerTests.cs} (66%) diff --git a/libraries/src/AWS.Lambda.Powertools.Common/Aspects/UniversalWrapperAspect.cs b/libraries/src/AWS.Lambda.Powertools.Common/Aspects/UniversalWrapperAspect.cs index fedf45031..8061ef7d0 100644 --- a/libraries/src/AWS.Lambda.Powertools.Common/Aspects/UniversalWrapperAspect.cs +++ b/libraries/src/AWS.Lambda.Powertools.Common/Aspects/UniversalWrapperAspect.cs @@ -83,7 +83,8 @@ public object Handle( }; var wrappers = triggers.OfType().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); } diff --git a/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/FunctionHandlerForGeneric.cs b/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/FunctionHandlerForGeneric.cs new file mode 100644 index 000000000..78f9c52db --- /dev/null +++ b/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/FunctionHandlerForGeneric.cs @@ -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 Handle(string input) + { + GenericMethod(1); + GenericMethod(2); + + GenericMethod(1); + + GenericMethod(); + GenericMethod(); + + GenericMethod2(1); + GenericMethod2(2); + + GenericMethod(); + GenericMethod(); + + await Task.Delay(1); + + return input.ToUpper(CultureInfo.InvariantCulture); + } + + [Tracing] + private T GenericMethod(T x) + { + return default; + } + + [Tracing] + private T GenericMethod() + { + return default; + } + + [Tracing] + private void GenericMethod2(T x) + { + } +} \ No newline at end of file diff --git a/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/ExceptionFunctionHandlerTests.cs b/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/HandlerTests.cs similarity index 66% rename from libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/ExceptionFunctionHandlerTests.cs rename to libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/HandlerTests.cs index 2f336abce..066d07438 100644 --- a/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/ExceptionFunctionHandlerTests.cs +++ b/libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/HandlerTests.cs @@ -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() @@ -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 + + } } \ No newline at end of file