Description
Description
In 80c440c, the logging behaviour for unhandled exceptions was changed. Exceptions are ToString()-ed and written to Console.Error.
This seems to "break" existing setups where structured logging is in place (ie Serilog). Logs are written twice, once by the application's own structured logging setup, then again to Console.Error using a non-structured approach.
We seem to be left with these options:
- Live with exceptions being logged twice, in two different ways.
- Skip the structured logging for unhandled exceptions, and live with the unstructured logging for unhandled exceptions.
- Downgrade to Amazon.Lambda.RuntimeSupport 1.5
If you have any other suggestions, please let me know!
Reproduction Steps
- Create a dotnet lambda (I use a custom runtime, but I don't think that changes anything)
- Setup Serilog or another structured logging library, configured to write to stdout
- Have the lambda listen to sqs messages, and deliberately throw an exception
- Make sure to have a try/catch around message processing that logs thrown exceptions using Serilog.
- Rethrow the exception to let Lambda retry the SQS message.
- Inspect the logs (you will now see a json string from Serilog AND numerous lines from the WriteUnhandledExceptionToLog method)
- Ship the logs to Datadog, or similar, that tries to understand the not-so-structured logs :)
Resolution
It would be nice if it was possible to disable the logging that the LambdaBootstrap does when an unhandled exception is thrown. Or perhaps have a way to provide a delegate that does the logging itself, so that we could have the LambdaBootstrap itself use structure logging.
Might not be a 🐛 bug-report, but causes problems for us at least :)