Skip to content

Conversation

@normj
Copy link
Member

@normj normj commented Apr 30, 2022

Description of changes:
If log messages contain newlines each line gets broken up over separate CloudWatch Logs. This is particular bad for stack traces. This is due to the runtime using STDOUT and STDERR for logging and the Lambda service doesn't know the start and stop of messages other then using newlines.

To fix this problem the .NET runtime will write log messages to the Lambda telemetry file descriptor if it is available. Otherwise fallback to STDOUT and STDERR. This is similar to the Java Lambda runtime.

Besides confirming all of the existing log tests a new stress test was added to confirm no threading issues and there was no affect to performance.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@normj normj force-pushed the normj/lambda-runtime-multiline-logging branch from 4f70db6 to c55cd34 Compare April 30, 2022 20:50
var stdOutWriter = FileDescriptorLogFactory.GetWriter(fileDescriptorLogId);
var stdErrorWriter = FileDescriptorLogFactory.GetWriter(fileDescriptorLogId);
Initialize(stdOutWriter, stdErrorWriter);
InternalLogger.GetDefaultLogger().LogInformation("Using file descriptor stream writer for logging.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this and ConsoleLoggerWriter.cs L53 log line appear same when logged? I believe there should be some prefix to differentiate the log lines emitted from different classes to make debugging easier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no precedence for adding a prefix when using InternalLogger.GetDefaultLogger(). If we really wanted to do something like that it would be implemented inside InternalLogger.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not blocking but I think worth considering, if two logs are shown same, and dev can't figure the origin, it creates some confusion.

Array.Reverse(messageLengthBytes);
}

var typeAndLength = ArrayPool<byte>.Shared.Rent(8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@normj normj force-pushed the normj/lambda-runtime-multiline-logging branch from c55cd34 to aaa032d Compare May 3, 2022 21:48
@normj normj merged commit b378338 into dev May 6, 2022
@normj normj deleted the normj/lambda-runtime-multiline-logging branch May 6, 2022 18:40
@svoychik
Copy link

Hi, I'm still experiencing this issue on .net 6 lambda runtime. Was the fix released to all AWS environments in all AWS regions?

@normj
Copy link
Member Author

normj commented May 13, 2022

It will take awhile for it to roll out when the next .NET patch is applied to the managed runtime. I don't know the exact Lambda rollout schedule but you can imagine code changes into Lambda are done very slowly and carefully.

If you need this fix today you can follow the pattern of our top-level statement project templates where the version of Amazon.Lambda.RuntimeSupport is included in the deployment bundle.

@svoychik
Copy link

svoychik commented Aug 3, 2022

@normj Hi. I've just checked and still see that the issue is still actual. I tried updating other AWS Nuget packages (Amazon.Lambda.RuntimeSupport, Amazon.Lambda.Core) but with no success - we still have not handled exception logs multilined

@svoychik
Copy link

svoychik commented Aug 3, 2022

Opened a bug to fix that #1265

@empty-space
Copy link

Issue still exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants