powertools-lambda-java icon indicating copy to clipboard operation
powertools-lambda-java copied to clipboard

Feature enhancement (Logger): automatically intercept Runtime exceptions, and log information

Open mriccia opened this issue 8 months ago • 7 comments

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

mriccia avatar Nov 22 '23 15:11 mriccia

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.

scottgerring avatar Nov 23 '23 07:11 scottgerring

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

jeromevdl avatar Nov 23 '23 08:11 jeromevdl

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.

jeromevdl avatar Nov 27 '23 17:11 jeromevdl

@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.

scottgerring avatar Nov 27 '23 18:11 scottgerring

@mriccia do you know what you want to do with this?

scottgerring avatar Nov 30 '23 09:11 scottgerring

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

mriccia avatar Nov 30 '23 10:11 mriccia

Completed for v2 as part of #1435

scottgerring avatar Dec 15 '23 12:12 scottgerring