Skip to content
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

LoggingFormat=JSON does not affect exception logging #1831

Open
1 task
Dreamescaper opened this issue Oct 7, 2024 · 5 comments
Open
1 task

LoggingFormat=JSON does not affect exception logging #1831

Dreamescaper opened this issue Oct 7, 2024 · 5 comments
Assignees
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.

Comments

@Dreamescaper
Copy link
Contributor

Dreamescaper commented Oct 7, 2024

Describe the bug

When I set lambda LoggingFormat to JSON, exception logs remains in TEXT format.

Regression Issue

  • Select this option if this issue appears to be a regression.

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.
image

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

@Dreamescaper Dreamescaper added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 7, 2024
@bhoradc bhoradc added needs-reproduction This issue needs reproduction. module/lambda-client-lib p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Oct 7, 2024
@bhoradc bhoradc self-assigned this Oct 7, 2024
@ashishdhingra
Copy link
Contributor

@Dreamescaper Good morning. Thanks for opening the issue. Please let us know the following:

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Oct 7, 2024
@Dreamescaper
Copy link
Contributor Author

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.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Oct 8, 2024
@Dreamescaper
Copy link
Contributor Author

@ashishdhingra

  1. No, we don't use AWS_LAMBDA_LOG_FORMAT log format, we configure it in Lambda Logging configuration:
    image

  2. I have updated Amazon.Lambda.Core to 2.3.0, nothing has changed.

@ashishdhingra
Copy link
Contributor

ashishdhingra commented Oct 8, 2024

@ashishdhingra

  1. No, we don't use AWS_LAMBDA_LOG_FORMAT log format, we configure it in Lambda Logging configuration:

image

  1. 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

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. and removed needs-reproduction This issue needs reproduction. labels Oct 8, 2024
@normj
Copy link
Member

normj commented Oct 9, 2024

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)"
  ]
}

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Oct 10, 2024
@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants