Open Dreamescaper opened 2 weeks ago
@Dreamescaper Good morning. Thanks for opening the issue. Please let us know the following:
AWS_LAMBDA_LOG_FORMAT
?Amazon.Lambda.Core
version 2.3.0
and see if the issue gets resolved?
(The support for structured JSON logging support was added in PR https://github.com/aws/aws-lambda-dotnet/pull/1803)Thanks, Ashish
I have a suspicion that this issue is already fixed, but is waiting for a managed runtime update on lambdas...
I'll provide the info you're asking a bit later.
@ashishdhingra
No, we don't use AWS_LAMBDA_LOG_FORMAT log format, we configure it in Lambda Logging configuration:
I have updated Amazon.Lambda.Core to 2.3.0, nothing has changed.
@ashishdhingra
- No, we don't use AWS_LAMBDA_LOG_FORMAT log format, we configure it in Lambda Logging configuration:
- I have updated Amazon.Lambda.Core to 2.3.0, nothing has changed.
@Dreamescaper The changes for structured logging would work as of now when using Amazon.Lambda.Core
version 2.3.0
when using executable assembly. For class library projects, we would need to wait for Lambda runtime to get updated. As of now we don't have exact ETA, but it could take few weeks. CC @normj
Are you deploying your function as an executable or class library? If you are deploying as an executable pulling in the latest versions of Amazon.Lambda.RuntimeSupport
and Amazon.Lambda.Core
then it should be working. It is the class library programming model we are waiting for the Lambda deployment to happen.
I'm assuming you are saying an exception that is thrown and not caught within your function handler. I just confirmed I got expected behavior with a function that does this:
var handler = (string input, ILambdaContext context) =>
{
if (string.Equals(input, "fail", StringComparison.InvariantCultureIgnoreCase))
{
throw new ArgumentException("You said fail");
}
return input.ToUpper();
};
// Build the Lambda runtime client passing in the handler to call for each
// event and the JSON serializer to use for translating Lambda JSON documents
// to .NET types.
await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync();
And get the following log message:
{
"timestamp": "2024-10-09T22:09:42.804Z",
"level": "Error",
"requestId": "2882bc48-17de-4d53-817e-b91aa1616a65",
"traceId": "Root=1-6706ff26-6370f67a168e1f2b3e1927ae;Parent=4fab4474991f77fa;Sampled=0;Lineage=1:ced1418f:0",
"message": null,
"errorType": "System.ArgumentException",
"errorMessage": "You said fail",
"stackTrace": [
"System.ArgumentException: You said fail",
"at Program.<>c.<<Main>$>b__0_0(String input, ILambdaContext context) in C:\\Users\\normj\\source\\repos\\StructuredLoggingWithException\\StructuredLoggingWithException\\Function.cs:line 10",
"at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass44_0`2.<GetHandlerWrapper>b__0(InvocationRequest invocation)",
"at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken)"
]
}
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
Describe the bug
When I set lambda LoggingFormat to JSON, exception logs remains in TEXT format.
Regression Issue
Expected Behavior
I would expect all logs from lambda published to CloudWatch in JSON format, including fail' exception logs.
Current Behavior
Exception logs are not in JSON format.
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
Amazon.Lambda.Core 2.3.0
Targeted .NET Platform
.NET 8
Operating System and version
AmazonLinux