Skip to content
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

WriteUnhandledExceptionToLog in LambdaBootstrap seems to break structured logging setup #1105

Closed
LarsAndreasEk opened this issue Mar 8, 2022 · 7 comments
Labels
feature-request A feature should be added or improved. module/lambda-client-lib p2 This is a standard priority issue queued response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.

Comments

@LarsAndreasEk
Copy link

LarsAndreasEk commented Mar 8, 2022

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:

  1. Live with exceptions being logged twice, in two different ways.
  2. Skip the structured logging for unhandled exceptions, and live with the unstructured logging for unhandled exceptions.
  3. Downgrade to Amazon.Lambda.RuntimeSupport 1.5

If you have any other suggestions, please let me know!

Reproduction Steps

  1. Create a dotnet lambda (I use a custom runtime, but I don't think that changes anything)
  2. Setup Serilog or another structured logging library, configured to write to stdout
  3. Have the lambda listen to sqs messages, and deliberately throw an exception
  4. Make sure to have a try/catch around message processing that logs thrown exceptions using Serilog.
  5. Rethrow the exception to let Lambda retry the SQS message.
  6. Inspect the logs (you will now see a json string from Serilog AND numerous lines from the WriteUnhandledExceptionToLog method)
  7. 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 :)

@LarsAndreasEk LarsAndreasEk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 8, 2022
@ashishdhingra ashishdhingra added feature-request A feature should be added or improved. module/lambda-client-lib and removed bug This issue is a bug. labels Mar 8, 2022
@ashishdhingra
Copy link
Contributor

Most likely a feature request rather than a bug.

@ashishdhingra ashishdhingra added needs-review and removed needs-triage This issue or PR still needs to be triaged. labels Mar 8, 2022
@martincostello
Copy link
Contributor

Might be related to #1000.

@bruce-lindsay
Copy link

@LarsAndreasEk this was an issue for me as well. As a workaround Console.SetError from the handler constructor with a custom implementation of a TextWriter which does nothing when WriteLine(object o) is called suppresses the output. I'm leaving this in case it helps anyone else. This worked for me because I don't use Console.Error from application code.

The new behavior should provide an opt-out for customers who are already using tools like Serilog.

@LarsAndreasEk
Copy link
Author

Thanks @bruce-lindsay! I put another workaround in place: Catch exceptions in our own code, log, then throw a custom exception that has a ToString implementation that returns null.

@ashishdhingra ashishdhingra added the p2 This is a standard priority issue label Dec 23, 2022
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Sep 19, 2024

@LarsAndreasEk Good afternoon. Structured logging support was added as part of PR #1803. Please refer to #1747 for details. Kindly check if it resolves your issue.

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Sep 19, 2024
@LarsAndreasEk
Copy link
Author

Glad to hear! I'm currently not working with that particular stack, so I will just take your word for it :)

Copy link
Contributor

Comments on closed issues 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. module/lambda-client-lib p2 This is a standard priority issue queued response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants