-
Notifications
You must be signed in to change notification settings - Fork 411
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(logger): add logger buffer feature #6060
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6060 +/- ##
===========================================
+ Coverage 96.25% 96.29% +0.03%
===========================================
Files 236 240 +4
Lines 11407 11571 +164
Branches 830 858 +28
===========================================
+ Hits 10980 11142 +162
Misses 337 337
- Partials 90 92 +2 ☔ View full report in Codecov by Sentry. |
The initial logic of buffering, checking the configuration, flushing and preserving all keys is working. Still need to improve things. from datetime import datetime
import os
from time import sleep
from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.buffer import LoggerBufferConfig
os.environ["_X_AMZN_TRACE_ID"] = "123"
logger_buffer_config = LoggerBufferConfig(max_size=10240, minimum_log_level="WARNING")
logger = Logger(level="INFO", logger_buffer=logger_buffer_config)
logger.append_keys(my_key="my_key")
logger.info("my log line with info - buffered")
logger.debug("my log line with debug - buffered")
print("Datetime log creation ---> ", datetime.now().strftime("%d/%m/%Y %H:%M:%S"), "<---- logs must have this timestamp")
sleep(5)
print("Datetime log flush [timestamp must be preserved] ---> ", datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
logger.flush_buffer() (venv) ➜ new-logger-buffer python meulog.py
Datetime log creation ---> 13/02/2025 23:13:28 <---- logs must have this timestamp
Datetime log flush [timestamp must be preserved] ---> 13/02/2025 23:13:33
{"level":"INFO","location":"<module>:14","message":"my log line with info - buffered","timestamp":"2025-02-13 23:13:28,744+0000","service":"service_undefined","my_key":"my_key","xray_trace_id":"123"}
{"level":"DEBUG","location":"<module>:15","message":"my log line with debug - buffered","timestamp":"2025-02-13 23:13:28,744+0000","service":"service_undefined","my_key":"my_key","xray_trace_id":"123"}
(venv) ➜ new-logger-buffer |
|
1 similar comment
|
|
It's missing only documentation and I think we are good to go. |
🚨 Status
Under Construction: This PR is a work in progress
Issue number: #4432
Summary
Changes
This pull request introduces a new logging buffer mechanism to optimize CloudWatch Logs cost and provide better debugging context during exceptions. Implement a smart log buffering system for AWS Lambda that captures debug context only when exceptions occur, reducing CloudWatch Logs costs.
The logging buffer will utilize a ring buffer implementation to manage memory efficiently, with a configurable buffer size that allows developers to control memory allocation and log retention. The mechanism will be designed with minimal performance overhead, ensuring that the log buffering process does not introduce significant computational cost or latency.
Checklist
Log Buffering
Error Handling
Testing
Documentation
User experience
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.