Skip to content

feat(logger): Flush buffer on uncaught error in Middy middleware #3690

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

Merged

Conversation

ConnorKirk
Copy link
Contributor

@ConnorKirk ConnorKirk commented Mar 3, 2025

Summary

This PR adds support for flushing the log buffer when an uncaught error is encountered using middy middleware.

Changes

Please provide a summary of what's being changed

  • Add flushBufferOnUncaughtError option to middy injectLambdaContext options
  • Add clearBuffer method to the logger. This is needed to clear the buffer in the onAfter handler. An alternative I considered was changing the logic of the buffer to only handle one trace id at a time. If a log is buffered with a new trace ID, then the buffer could be reset.
  • Split the injectLambdaContextAfterOrOnError into separate handlers . Simplify the names all the handlers.

Notes

  • The target parameter of injectLambdaContext can be an array of loggers. I wasn't clear on the correct behaviour if there are multiple loggers provided. At the moment it will flush each logger.

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: #3633


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added logger This item relates to the Logger Utility tests PRs that add or change tests labels Mar 3, 2025
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Mar 3, 2025
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Mar 4, 2025
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR Connor! Left a couple comments here & there but I think we are very close

@ConnorKirk ConnorKirk force-pushed the 3633-middy-flush-buffer-on-error branch from 35095d9 to 02e1440 Compare March 4, 2025 11:01
@dreamorosi dreamorosi self-requested a review March 4, 2025 13:23
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work on this feature, Connor!

This should be the last PR for this feature - we'll write the docs in the next days and expect to ship it on Friday.

@dreamorosi dreamorosi merged commit 23eebe4 into aws-powertools:main Mar 4, 2025
41 checks passed
@ConnorKirk ConnorKirk deleted the 3633-middy-flush-buffer-on-error branch March 5, 2025 14:16
@dreamorosi dreamorosi linked an issue Mar 7, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes logger This item relates to the Logger Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: flush buffer on uncaught error - Middy.js middleware
2 participants