|
2 | 2 |
|
3 | 3 | const cjsHook = require('@serverless/sdk/lib/instrumentation/utils/cjs-hook');
|
4 | 4 | const instrumentV2Sdk = require('../../../instrumentation/aws-sdk-v2').install;
|
5 |
| -const instrumentV3Client = require('../../../instrumentation/aws-sdk-v3-client').install; |
6 |
| - |
7 |
| -const instrumentedv3SmithyClients = new WeakMap(); |
| 5 | +const instrumentSmithyClient = require('../../../instrumentation/smithy-client').install; |
8 | 6 |
|
9 | 7 | module.exports.install = () => {
|
10 | 8 | // AWS SDK v2
|
11 | 9 | cjsHook.register('/aws-sdk/lib/core.js', instrumentV2Sdk);
|
12 | 10 |
|
13 | 11 | // AWS SDK v3
|
14 | 12 | cjsHook.register('/@aws-sdk/smithy-client/dist-cjs/client.js', ({ Client }) => {
|
15 |
| - if (instrumentedv3SmithyClients.has(Client)) return instrumentedv3SmithyClients.get(Client); |
16 |
| - const originalSend = Client.prototype.send; |
17 |
| - const uninstallers = new Set(); |
18 |
| - Client.prototype.send = function send(command, optionsOrCb, cb) { |
19 |
| - try { |
20 |
| - uninstallers.add(instrumentV3Client(this)); |
21 |
| - } catch (error) { |
22 |
| - serverlessSdk._reportError(error); |
23 |
| - } |
24 |
| - return originalSend.call(this, command, optionsOrCb, cb); |
25 |
| - }; |
26 |
| - const uninstall = () => { |
27 |
| - if (!instrumentedv3SmithyClients.has(Client)) return; |
28 |
| - for (const uninstallClient of uninstallers) uninstallClient(); |
29 |
| - Client.prototype.send = originalSend; |
30 |
| - instrumentedv3SmithyClients.delete(Client); |
31 |
| - }; |
32 |
| - instrumentedv3SmithyClients.set(Client, uninstall); |
33 |
| - return uninstall; |
| 13 | + return instrumentSmithyClient(Client); |
| 14 | + }); |
| 15 | + |
| 16 | + cjsHook.register('/@smithy/smithy-client/dist-cjs/client.js', ({ Client }) => { |
| 17 | + return instrumentSmithyClient(Client); |
34 | 18 | });
|
35 | 19 | };
|
36 | 20 |
|
37 | 21 | module.exports.uninstall = () => {
|
38 | 22 | cjsHook.unregister('/aws-sdk/lib/core.js');
|
39 | 23 | cjsHook.unregister('/@aws-sdk/smithy-client/dist-cjs/client.js');
|
40 | 24 | };
|
41 |
| - |
42 |
| -const serverlessSdk = require('../../../'); |
0 commit comments