Skip to content

feat(logger): clear state when other middlewares return early - #1544

Merged
dreamorosi merged 1 commit into
mainfrom
1534-feature-request-populate-middys-requestinternal-with-cleanup-function-for-logger
Jun 22, 2023
Merged

feat(logger): clear state when other middlewares return early#1544
dreamorosi merged 1 commit into
mainfrom
1534-feature-request-populate-middys-requestinternal-with-cleanup-function-for-logger

Conversation

@dreamorosi

Copy link
Copy Markdown
Contributor

Description of your changes

This PR introduces new logic to the injectLambdaContext() Middy middleware offered by Logger to allow it to clean its state whenever another middleware down in the stack returns early.

This is made possible by the cleanupMiddlewares function shipped in commons in the previous release. The new logic sets a reference to a cleanup function in the Middy internal storage using a scoped key. This way, Middy middlewares that want to return early can call the cleanupMiddlewares function which will execute all the cleanup functions available. This is useful for those middlewares like Idempotency, that want to return a result bypassing the Lambda handler and the normal Middy request lifecycle.

I have also added a unit test case to verify that the cleanup logic is executed.

Related issues, RFCs

Issue number: #1534

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

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.

@dreamorosi
dreamorosi requested a review from a team June 22, 2023 13:02
@dreamorosi dreamorosi self-assigned this Jun 22, 2023
@boring-cyborg boring-cyborg Bot added logger This item relates to the Logger Utility tests PRs that add or change tests labels Jun 22, 2023
@pull-request-size pull-request-size Bot added the size/M PR between 30-99 LOC label Jun 22, 2023
@github-actions github-actions Bot added the feature PRs that introduce new features or minor changes label Jun 22, 2023
@dreamorosi

Copy link
Copy Markdown
Contributor Author

@am29d am29d left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

super clean, thanks to the previous work 👍

@dreamorosi
dreamorosi marked this pull request as draft June 22, 2023 14:16
@dreamorosi
dreamorosi marked this pull request as ready for review June 22, 2023 14:26
@dreamorosi
dreamorosi merged commit d5f3f13 into main Jun 22, 2023
@dreamorosi
dreamorosi deleted the 1534-feature-request-populate-middys-requestinternal-with-cleanup-function-for-logger branch June 22, 2023 14:27
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/M PR between 30-99 LOC tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: populate middy's request.internal with cleanup function for Logger

2 participants