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

feat(lambda): support for advanced logging #28039

Merged
merged 8 commits into from
Nov 16, 2023
Merged

Conversation

otaviomacedo
Copy link
Contributor

Structured logging enables automated analysis of the logs, thus enables customers to perform quick exploratory and automated monitoring the health of their applications, and helps them troubleshoot their production issues faster. Structured logging is now considered to be a monitoring best practice.

Lambda is developing Advance Logging Controls to give developers and operators more control over their function logs. The feature allows customers to capture logs in JSON format and control the level of details in emitted logs. To ensure compatibility and enable these capabilities, four new fields (LogFormat, ApplicationLogLevel, SystemLogLevel, and LogGroup) will be added to the existing LoggingConfig structure. Also, even adding custom log group for Log group section to have the flexibility of changing the name instead of having it as default. This update empowers customers to define their logging behavior and efficiently manage their function logs, reflecting Lambda's commitment to delivering a user-friendly logging solution that addresses the evolving needs of users.


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

@aws-cdk-automation aws-cdk-automation requested a review from a team November 16, 2023 17:44
@github-actions github-actions bot added the p2 label Nov 16, 2023
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 16, 2023
@kaizencc kaizencc self-requested a review November 16, 2023 17:52
@otaviomacedo otaviomacedo added the pr/do-not-merge This PR should not be merged at this time. label Nov 16, 2023
@otaviomacedo otaviomacedo removed the pr/do-not-merge This PR should not be merged at this time. label Nov 16, 2023
Copy link
Contributor

mergify bot commented Nov 16, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 29e50af
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 3278c19 into main Nov 16, 2023
12 checks passed
@mergify mergify bot deleted the otaviom/cdk_advance_logging_2 branch November 16, 2023 19:19
Copy link
Contributor

mergify bot commented Nov 16, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

* Sets the logFormat for the function.
* @default Text format
*/
readonly logFormat?: string;
Copy link
Contributor

@jogold jogold Nov 16, 2023

Choose a reason for hiding this comment

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

Why is this not typed (enum)? Same for log level.

(there's still time to change this before it becomes a breaking change)

Copy link
Contributor

Choose a reason for hiding this comment

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

haa i see.

Copy link
Contributor

Choose a reason for hiding this comment

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

A breaking change can be avoided by setting the type to LogFormat | keyof typeof LogFormat which would allow using either the enum or type-safe strings as the value.

Suggested change in #28127 which aims to solve this.

Copy link

@tomoish tomoish Nov 28, 2023

Choose a reason for hiding this comment

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

Thank you for your suggestion.
if LogFormat type is changed to logFormat?: LogFormat | keyof typeof LogFormat;, An error like the following occurs in the code: logFormat: 'Text'.
Type '"Text"' is not assignable to type 'LogFormat | "TEXT" | "JSON" | undefined'. Did you mean '"TEXT"'?ts(2820)
Would you mind telling me a solution that accepts both lambda.LogFormat.TEXT and string 'Text'.

Copy link

Choose a reason for hiding this comment

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

I might solve this problem by myself. I suggest changes in #28127.

mergify bot pushed a commit that referenced this pull request Jan 17, 2024
…up` (#28737)

#28039 introduced support for custom logging configurations for AWS Lambda Functions.

This change deprecates the `logRetention`, `logRetentionRole` and `logRetentionRetryOptions` properties in favor of using a custom logging configuration.

By default, Lambda functions send logs to an automatically created default log group named `/aws/lambda/<function name>`. However you cannot change the properties of this auto-created log group using the AWS CDK, e.g. you cannot set a different log retention. To overcome the limitation, a custom resource was introduced and configuration exposed via the `logRetention` properties. This is what we are deprecating in this change.

With the introduction of custom logging configuration and the new `logGroup` property, users can now create a fully customizable `LogGroup` ahead of time, and instruct the Lambda function to send logs to it.

Migrating from `logRetention` to `logGroup` will cause the name of the log group to change. Don't attempt to use the name of the auto-created log group, this will cause subtle issue. We recommend using auto-naming for lambda log groups, they can easily be accessed via the Lambda Console. If you want use a well-known name, we recommend using a pattern like `/<your service>/lambda/<function name>`. Be aware that a names log group can prevent a stack from being recreated without manual intervention after it has been deployed (error `Resource already exists`). This is because `LogGroups` are retained by default.

Either way, users will have to adjust and documentation will need to be updated. Any code referencing the old log group name verbatim will have to be changed as well. Keep in mind that in AWS CDK code, you can access the log group name directly from the `LogGroup` construct: 
```ts
declare const myLogGroup: logs.LogGroup;
myLogGroup.logGroupName;
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants