-
Notifications
You must be signed in to change notification settings - Fork 26
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
Bug: Tracing throws a reflection exception when handling aggregate exception #769
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @AdithyaAthreya, thank you for opening the issue, after some careful consideration we don't believe this is an issue and our reasoning is that the error and stack trace you are seeing looks correct. The stack trace accurately reflects the code's execution path, which necessarily includes the Tracing. We recommend accepting this as expected behaviour unless stack trace purity is an absolute requirement. The stack trace will always include the AOP (Tracing) because:
Example stack trace
Some issues in your example
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); // This is wrong
} Updated examplepublic async Task<string> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
try
{
await TestExceptionMethod();
return "Success";
}
catch (Exception ex)
{
var extraKeys = TransformToAcceptableFormat(ex.Data);
Logger.LogError(extraKeys: extraKeys, exception: ex,
message: "Exception in ServiceMenu-Delta retrieval");
// Either rethrow the original exception
throw;
// Or if you must return an API error, wrap the original exception
// throw new InternalServerErrorException(errorBody, ex);
}
}
Let me know if you have any questions. |
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
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
The text was updated successfully, but these errors were encountered: