powertools-lambda-java
powertools-lambda-java copied to clipboard
Feature enhancement (Logger): automatically intercept Runtime exceptions, and log information
Is your feature request related to a problem? Please describe.
When using the Powertools Logger, log lines are annotated with a number of useful fields such as function_request_id
.
However, if a Runtime exception is thrown, Powertools Logger isn't used to log the exception. Instead the exception is printed using the System.err
by the JVM, and the log lines do not contain any information relating to the function execution.
Describe the solution you'd like
I would like the RuntimeExceptions to be printed, so when exceptions are raised in my code, I can identify the function_request_id
for further debugging
Describe alternatives you've considered
It is possible for Powertools users to define their own catching mechanism, however it would be nice if Powertools Logger printed this information by default
Additional context
The logger aspect could:
- Catch and log at an appropriate level in a structured fashion
- Rethrow
We'll get the error twice in the logs - once structured once stdout, but i'd be hesitant to interfere with the runtime itself seeing the exception too.
we can't avoid the runtime to log, unless we catch the exception completely, but we cannot do that, if the function is in error the caller must be aware, so just catch / log (fatal) / rethrow
Do we add this to v1 or v2? While I'm working on logging v2, I can do it, but if we do in v1, I let @mriccia.
@mriccia if you feel especially attached to it lets add it in v1, otherwise I don't think we should push new features there as discussed.
@mriccia do you know what you want to do with this?
IMO we should add it in v2, as I only saw this request from customers once and does not appear to be a big issue
Completed for v2 as part of #1435