-
Notifications
You must be signed in to change notification settings - Fork 153
Feature request: allow enabling log buffering via constructor #3634
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
Comments
Hey @leandrodamascena, I can't remember if we agreed on a default size for the log buffer in bytes. I checked the RFC but I didn't write it down. What do you think we should put? |
Hello @dreamorosi! I was testing and I came up with an arbitrary value of 20480 in Python. I saw that the information I save in buffer has on average 200 bytes, so I calculated more or less 100 lines of debug. It seems to be a reasonable number, but since this is still a long way off, what do you think? Also:
In Python, I consider that if the Buffer object is passed to the constructor, it will always be true, so I removed this field. I think having the |
I initially thought the same, but what if customers want to enable the buffering but leave every other setting with default values? They'd have to do this in JS const logger = new Logger({
logLevel: 'WARN',
bufferConfig: {} // buffer is enabled, with default max size, and other default options
}); Imo this is kind of ugly, so I thought of making it explicit by adding const logger = new Logger({
logLevel: 'WARN',
bufferConfig: { // this means enabled
maxBytes: 12345,
}
}); You're right - I'll update the issue. For the size, I don't have any strong feelings and will go with the number that you got from the tests. Thank you for the quick reply! |
I'll work on this next |
Hi @dreamorosi and @ConnorKirk! I don't know if I'm wrong, but I don't see Am I wrong? By the way, excellent implementation of |
I think the buffer is specific to the request/trace id, so it will start from scratch at the next request. Or at least that was the intent; I need to check the implementation again on Monday. |
Another question: when you can't add an item to the buffer, probably because it is larger than the entire buffer size, you are adding a logger warning level. Should this be a system warning message instead of a log? I would rather raise a waning, the same as we do with metrics and others, instead of a logger warning. In Python it makes more sense to be a warning, I don't know about the TS/JS ecosystem, but it seems to be the same thing. |
There's a warning module similar to what you're referring to in the Node.js standard lib, but in Lambda it gets treated as a thrown error. If we don't handle it, customers will see an actual error in their metrics and logs. If we handle it, functionally speaking, we would end up to the same result of just us calling Since it'd be just an entry in CloudWatch (current implementation) or an actual unhandled error, I opted for the app warning. |
You're correct, This might be slightly off-spec - in which case I'm happy to change it. |
Hi @ConnorKirk! Thanks for the detailed explanation! I read the code again and I was able to understand the implementation better! In Python (it's true for TS too), I assume that we will never have 2 keys in the buffer due to the Lambda execution model, that is, when the invocation arrives, I need to clear the entire instance and not just the specific key. But this TypeScript implementation makes more sense because it better defines the responsibility of the Thanks a lot for your contributions here! |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
Use case
In #3617 we have implemented a mechanism to buffer logs. The next step in the implementation is to make the feature configurable via constructor options.
Solution/User Experience
Customers should be able to configure log buffering via constructor options.
The
ConstructorOptions
type/object is already pretty crowded (link), so we should add the new settings as a nested object.In practice, we should add a new optional
bufferConfig
object toConstructorOptions
and this object should have the following keys all optional:enabled
: boolean (defaults totrue
)maxBytes
- this allows customers to configure the max size of the buffer in bytes (optional defaults to1024
)flushOnErrorLog
- this allows customers to toggle whether the buffer is flushed when callinglogger.error()
(optional defaults totrue
)bufferAtVerbosity
- this allows customers to configure the threshold at which we'll buffer logs (optional defaults toDEBUG
|debug
, acceptsTRACE
,DEBUG
,INFO
, andWARN
plus their corresponding small case versions - you can never bufferERROR
logs)The configuration logic of the Logger can be found in the
setOptions()
method. The order in which things are initialized in this method matters, but for this feature I can't think of any dependency so I'd just add it at the end here.To follow the existing pattern, we should add a new
#setLogBuffering()
method (feel free to use a better name as long as it starts with the#set
prefix). This method:ConstructorOptions['bufferConfig']
is presentConstructorOptions['bufferConfig']
object#buffer
here, since the max size is know only at this point)Then, after this is added, we should also:
flushBuffer()
method publicLoggerInterface
error()
method to flush the buffer if log buffering is enabled &&flushOnErrorLog
istrue
Besides the implementation, we should update the unit tests that use the feature to now use both the public config and new public methods as well as add tests for the new config + flush-on-error behavior. Likewise, we should make sure the new types are added and documented properly (see other types in the same file for reference).
Alternative solutions
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: