Description
Expected Behaviour
Aggregate exceptions are handled correctly by the power tools tracing library.
Current Behaviour
I am currently working with a .NET 8 AWS lambda which is asynchronous and invoked from AWS api gateway. From the async function handler itself, I call another async method which throws an exception. When tracing is handling this aggregate exception, I get a reflection related exception in my logs. A screenshot of the output response of the lambda has been attached.
I did read this post: #223. But this doesn't seem to fix the current exception I'm getting.
Code snippet
namespace TestCode
{
public class Function
{
[Tracing(CaptureMode = TracingCaptureMode.EnvironmentVariable))]
[Logging(ClearState = true, LogEvent = true, LoggerOutputCase = LoggerOutputCase.CamelCase)]
public async Task<string> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
try
{
await TestExceptionMethod();
}
catch (AggregateException ex)
{
if(ex.InnerException is NotImplementedException)
{
throw new Exception("NotImplementedException block of aggregate exception");
}
throw new Exception("Exception block of aggregate exception");
}
catch (Exception ex)
{
var extraKeys = TransformToAcceptableFormat(ex.Data);
Logger.LogError(extraKeys: extraKeys, exception: ex,
message: "Exception in ServiceMenu-Delta retrieval");
var errorBody = GenerateErrorObject(errorCode: HttpStatusCode.InternalServerError,
ErrorTitles.INTERNAL_SERVER_ERROR_TITLE,
[ex.Message]);
throw new InternalServerErrorException(errorBody);
}
}
[Tracing(CaptureMode = TracingCaptureMode.Error)]
private async Task TestExceptionMethod()
{
await Task.Delay(10);
throw new Exception("from test exception method");
}
}
}
Possible Solution
No response
Steps to Reproduce
Add the above code snippet in a lambda project and upload to AWS
Setup a simple AWS api gateway GET endpoint and invoke it from postman
Observe the response returned by the api call in postman
Observe the cloudwatch logs and traces
Powertools for AWS Lambda (.NET) version
1.6.0
AWS Lambda function runtime
dotnet8
Debugging logs
Metadata
Metadata
Assignees
Type
Projects
Status