[v8] Fix AWS Lambda plugin not waiting for Event requests when used with server plugins #2120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
In v8 we moved the responsibility for cloning a request-scoped client from the session plugin to the server plugins (express, Koa & restify). However, we missed that the AWS Lambda plugin still expects the session plugin to clone the clients when using a server integration:
bugsnag-js/packages/plugin-aws-lambda/src/session.js
Lines 11 to 16 in 2f1ed64
The in-flight plugin (used by the AWS Lambda plugin to wait for outstanding requests to finish) relies on monkey patching the
Client#notify
method and this patch has to be reapplied to cloned clients or it won't be able to track event requests anymore:bugsnag-js/packages/in-flight/src/in-flight.js
Lines 9 to 12 in 2f1ed64
In v7 this works because the AWS Lambda plugin has a copy of the
clone-client.js
file from@bugsnag/core
in its built bundle and is responsible for both registering the on clone callback and cloning the client. Now that the Express plugin is cloning the client, the AWS Lambda plugin registers its on clone callback on a different copy ofclone-client.js
than the one used by the Express plugin to do the cloning. This means the newly cloned request client will not have thenotify
monkey patch applied and therefore any Events it sends cannot be trackedGiven that these plugins run in a node environment, we don't actually need to bundle them at all — it was primarily done to run them through babel for old Node versions but that's no longer necessary in v8, which has a minimum Node version of v12
Therefore the fix is as simple as:
We may also want to look at removing the build steps from all other plugins that are exclusively used in Node (browser plugins will still need to be bundled) to stop this kind of bug from happening again